Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2008

Tip: Looking for answers? Try searching our database.

Print msgbox or print string values?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dandeli0n - 28 Feb 2008 14:06 GMT
At the end of my Word macro I use a msgbox filled with text and the value of
some strings

is it possible to print the value of these strings in a document or to print
the msgbox as a whole?
Greg Maxey - 28 Feb 2008 14:23 GMT
Sub ScratchMacro()
Dim pStr1 As String
Dim pStr2 As String
pStr1 = "Alpha, Bravo, Charlie ..."
pStr2 = "...Yankee, Xray, Zulu"
'Instead of:
MsgBox pStr1 & pStr2
'Use:
Dim oDoc As Document
Set oDoc = Documents.Add
oDoc.Range.Text = pStr1 + pStr2
oDoc.PrintOut
oDoc.Close wdDoNotSaveChanges
End Sub

Signature

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey -  Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> At the end of my Word macro I use a msgbox filled with text and the
> value of some strings
>
> is it possible to print the value of these strings in a document or
> to print the msgbox as a whole?
Dandeli0n - 28 Feb 2008 15:07 GMT
Dear Greg,

this looks very promising! Thank you

How can i specify the font and so on for this document?

And, can I use "& vbcrlf" for line breaks?

Again, thank you!
Dande

> Sub ScratchMacro()
> Dim pStr1 As String
[quoted text clipped - 16 lines]
> > is it possible to print the value of these strings in a document or
> > to print the msgbox as a whole?
Greg Maxey - 28 Feb 2008 15:40 GMT
I didn't try vbCrlf but you can use vbCr:

Sub ScratchMacro()
Dim pStr1 As String
Dim pStr2 As String
pStr1 = "Alpha, Bravo, Charlie ..."
pStr2 = "...Yankee, Xray, Zulu"
'Instead of:
MsgBox pStr1 & pStr2
'Use:
Dim oDoc As Document
Set oDoc = Documents.Add
With oDoc.Range
 .Text = pStr1 & vbCr & pStr2
 .Font.Name = "Arial Black"
 .Font.Size = "24"
End With
oDoc.PrintOut
oDoc.Close wdDoNotSaveChanges
End Sub

Signature

~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey -  Word MVP

My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> Dear Greg,
>
[quoted text clipped - 27 lines]
>> > is it possible to print the value of these strings in a document or
>> > to print the msgbox as a whole?
Dandeli0n - 29 Feb 2008 14:58 GMT
Greg,

it seemed to work, but when I enter my own string  strTeller I receive an
error 13

here's the complete code:
Option Explicit

Private Const pad1 As String = "\\test path\1\"
Private Const pad2 As String = "\\test path\2\"
Private Const pad3 As String = "\\test path\3\"
Private Const pad4 As String = "\\test path\4\"
Private Const pad5 As String = "\\test path\5\"
Private Const pad6 As String = "\\test path\6\"
Private Const pad7 As String = "\\test path\7\"
Private Const pad8 As String = "\\test path\8\"
Private Const pad9 As String = "\\test path\"
Private Const Printer1 As String = "printer name"

Dim StrStandaardprinter As String
Dim Brieventeller1 As Integer
Dim Brieventeller2 As Integer
Dim Brieventeller3 As Integer
Dim Brieventeller4 As Integer
Dim Brieventeller5 As Integer
Dim Brieventeller6 As Integer
Dim Brieventeller7 As Integer
Dim Brieventeller8 As Integer

Private Declare Function apiGetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Const MAX_PATH As Integer = 255
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub StandaardPrinter()
'maak gebruik van de door de gebruiker ingestelde standaard printer

   ActiveDocument.PrintOut
   MsgBox "document wordt nu op de standaard afdelingsprinter geprint",
vbInformation, "Standaard printer"

End Sub

Function fncPrintMap(strZOEKPAD As String, strDocNaam As String, strSepPage
As String, strTeller As Integer, strDocSoort As String)
'***************************************************
'deze code is voor iemand van FSB die de docs in één keer moet printen
'***************************************************
'deze functie maakt een map aan voor reserve kopieën van de bestanden
'dan worden alle gevonden bestanden (per stuk) naar deze backupmap gekopieerd,
'geprint en uit de hoofdmap gewist.
'***************************************************
Dim DagBackupMap As String
'Dim strTeller As String
Dim StrStandaardprinter As String

'printeroutput moet naar een andere dan de huidig ingestelde printer....
'bepaal standaardprinter en zet aan het einde van de printactie de
standaardprinter weer terug

   'haal de naam van de huidige printer op
   StrStandaardprinter = ActivePrinter
   
       'gebruik tijdelijk een andere printer
       With Dialogs(wdDialogFilePrintSetup)
       .printer = Printer1
       .DoNotSetAsSysDefault = True
       .Execute
       End With
       
' Print batch specifiek scheidingspagina
   ChangeFileOpenDirectory pad9
   With ActiveDocument.PageSetup
       .FirstPageTray = wdPrinterUpperBin
       .OtherPagesTray = wdPrinterUpperBin
   End With
 
   Application.PrintOut FileName:=strSepPage

strTeller = 0   'teller die aan het einde van de printactie wordt getoond

DagBackupMap = strZOEKPAD & Format(Date, "yyyymmdd") & "\"
'aanmaken van de dagbackupmap
On Error GoTo foutafhandeling
MkDir DagBackupMap

Dim strfILE As String
' Haal alle gezochte bestanden op in de opgegeven map
strfILE = Dir(strZOEKPAD & strDocNaam)
   Do Until strfILE = ""
   'Debug.Print strfILE 'test of het werkt
   
   'copy het gevonden bestand naar de dag-backupmap
   FileCopy strZOEKPAD & strfILE, DagBackupMap & strfILE
   'print het gevonden document
           Application.PrintOut FileName:=strZOEKPAD & strfILE,
Background:=False
           strTeller = strTeller + 1
   'onderstaande SLEEP is nodig omdat het document nog niet naar de printer
is, terwijl
   'het al gewist moet worden en de KILL niet altijd goed werkt
   Sleep (0)           ' Wacht 1 seconde (1000 msec.)

   'wissen van het zojuist gekopieerde en geprinte document
       Kill strZOEKPAD & strfILE
   'zoek verder naar het volgende document
   strfILE = Dir
   
   Loop
   
   'Print een scheidingspagina met het aantal geprinte documenten
   Dim pStr1 As String
   Dim pStr2 As String
   pStr1 = "Er zijn "
   pStr2 = "brieven geprint."
   Dim oDoc As Document
   Set oDoc = Documents.Add
   With ActiveDocument.PageSetup
       .FirstPageTray = wdPrinterUpperBin
       .OtherPagesTray = wdPrinterUpperBin
   End With
   With oDoc.Range
       .Text = pStr1 + strTeller + pStr2
       .Font.Name = "Verdana"
       .Font.Size = "18"
       .Font.Bold = True
   End With
   oDoc.PrintOut
   oDoc.Close wdDoNotSaveChanges
   
   Exit Function

foutafhandeling:
   If Err.Number = 75 Or Err.Number = 70 Then
       'directory bestaat al
       Resume Next
   ElseIf Err.Number = 70 Then 'bestand is in gebruik
       Resume Next
   Else
       MsgBox "Hier gaat iets niet helemaal goed!!!" & vbCrLf &
"foutmelding: " & Err.Number
   'terugzetten naar de oorspronkelijke printer omdat anders de
standaardprinter is gewijzigd
   ActivePrinter = StrStandaardprinter

       Exit Function
   End If

End Function

Sub MessageBox()

'********* alle gevonden documenten zijn geprint

   'Als er geen documenten meer zijn:
           MsgBox "Er zijn " & vbCrLf & Brieventeller1 & " Enkelvoudige DL
A&M brieven geprint" & vbCrLf & Brieventeller2 & " meervoudige DL A&M brieven
geprint" & vbCrLf & Brieventeller3 & " enkelvoudige DL Claims brieven
geprint" & vbCrLf & Brieventeller4 & " meervoudige DL Claims brieven geprint"
& vbCrLf & Brieventeller5 & " enkelvoudige OHRA brieven geprint" & vbCrLf &
Brieventeller6 & " meervoudige OHRA brieven geprint" & vbCrLf &
Brieventeller7 & " DL restant brieven geprint" & vbCrLf & Brieventeller8 & "
OHRA restant brieven geprint", vbInformation, "Centraal afdrukken brieven"
   'terugzetten naar de oorspronkelijke printer
   ActivePrinter = StrStandaardprinter

End Sub

Sub PrintPGSDocumenten()

   Call fncPrintMap(pad1, "d*.doc", "doc1.doc", Brieventeller1, "test text ")

   Call fncPrintMap(pad2, "d*.doc", "doc2.doc", Brieventeller2, "test text ")

   Call fncPrintMap(pad3, "d*.doc", "doc3.doc", Brieventeller3, "test text ")

   Call fncPrintMap(pad4, "d*.doc", "doc4.doc", Brieventeller4, "test text ")
   
   Call fncPrintMap(pad5, "d*.doc", "doc5.doc", Brieventeller5, "test text ")
   
   Call fncPrintMap(pad6, "d*.doc", "doc6.doc", Brieventeller6, "test text ")

   Call fncPrintMap(pad7, "d*.doc", "doc7.doc", Brieventeller7, "test text ")

   Call fncPrintMap(pad8, "d*.doc", "doc8.doc", Brieventeller8, "test text ")
   
   Call MessageBox
   
End Sub

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.