Thank you, Jean-Guy.
Could've sworn I posted this response... anyway...
Jean-Guy Marcil said:
You keep showing us code snippets, we must see the whole thing (you may not
show us the appropriate snippets...).
Also, I get the feeling that there are two separate procedures, is that right?
Yes. Two procedures. The second procedure is in another post below. Account
numbers/details are fake:
***********
Public Sub MAIN()
Dim FilName$
Dim FirstWin$
Starter:
On Error GoTo Trouble
WordBasic.BeginDialog 268, 166, "Microsoft Word"
WordBasic.GroupBox 33, 15, 202, 110, "Type of Merge:"
WordBasic.OKButton 41, 132, 88, 21
WordBasic.CancelButton 137, 132, 88, 21
WordBasic.OptionGroup "InvType"
WordBasic.OptionButton 46, 36, 133, 16, "&Letterhead Invoice" '0
WordBasic.OptionButton 46, 56, 132, 16, "&PDF Invoice" '1
WordBasic.OptionButton 46, 76, 132, 16, "&Ringer Invoice" '2
WordBasic.OptionButton 46, 96, 132, 16, "&Bank Deposits" '3
WordBasic.EndDialog
Dim dlg As Object: Set dlg = WordBasic.CurValues.UserDialog
WordBasic.Dialog.UserDialog dlg
If dlg.InvType = 0 Then
FilName$ = "inv_merg.doc"
ElseIf dlg.InvType = 1 Then
FilName$ = "invPDFmerg.doc" ' was invfmerg.doc for VIA FAX
ElseIf dlg.InvType = 2 Then
FilName$ = "Invoice Telus Merge" '
ElseIf dlg.InvType = 3 Then
FilName$ = "Bank Deposit Form.doc" '
Application.Run "Normal.SuperbaseBankDeposits.MAIN"
GoTo EndItAll
End If
' Open the Invoice merge doc and perform merge.
WordBasic.FileOpen Name:="c:\windows\winword\merge\" + FilName$,
ReadOnly:=0, PasswordDoc:="", PasswordDot:=""
FirstWin$ = WordBasic.[WindowName$]() 'get title of current window
WordBasic.WW2_PrintMergeToDoc Suppression:=0 ' do merge
WordBasic.StartOfDocument
WordBasic.Activate FirstWin$
WordBasic.FileClose
Trouble:
If Err.Number = 509 Then 'Error 509: happens when no docs are open
WordBasic.FileNewDefault 'creates a blank doc
Err.Number = 0 'Reset error trap
Else 'If a different error occurs
GoTo EndItAll
End If
EndItAll:
' The following prints Ringer invoice to PDF file:
If FilName$ = "Ringer Invoice" Then
Selection.Find.ClearFormatting
With Selection.Find
..Text = "Invoice #"
..Replacement.Text = "Total Owing"
..Forward = True
..Wrap = wdFindContinue
..Format = False
..MatchCase = False
..MatchWholeWord = False
..MatchWildcards = False
..MatchSoundsLike = False
..MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
ActivePrinter = "Adobe PDF"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False
WordBasic.StartOfDocument
WordBasic.FileOpen Name:="c:\windows\winword\merge\Invoice Ringer Email"
FirstWin$ = WordBasic.[WindowName$]() 'get the title of the current window
With ActiveDocument.MailMerge
..Destination = wdSendToNewDocument
..Execute
End With
WordBasic.Activate FirstWin$
' FileClose
WordBasic.DocClose 2
ActiveDocument.SaveAs FileName:="C:\Documents and Settings\All
Users\Desktop\Invoice.eml", FileFormat _
:=wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True _
, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
RetVal = Shell("C:\Program Files\Outlook Express\msimn.exe /eml:C:\Documents
and Settings\All Users\Desktop\Invoice.eml", vbNormalFocus)
WordBasic.DocClose 2
End If
End If
End Sub