Expected: End of Statment

Banimo

New Member
Joined
Sep 22, 2014
Messages
7
I'm trying to active a Word document to reference it as the 'ActiveDocument', however i am facing an "Expected end of Statement" error.

Here's the code:

Code:
Private Sub OpenWrd()
    
    Dim wdApp As Word.Application, MyDoc As Word.Document
    Dim objWord As New Word.Application
    
    Set wdApp = CreateObject("Word.Application")
    wdApp.Visible = True
    wdApp.WindowState = wdWindowStateMaximize
    
    Set MyDoc = wdApp.Documents.Add("G:\Everyone\QP12 JSY Maturity Advice.docx")
    
    With MyDoc
        
        With .MailMerge
            .OpenDataSource Name:="\\sbojsyfps001\data\Home\banimb\Data\Documents\BenAdmin\Save test (sub)\TestSave2.xlsx"
            .SuppressBlankLines = True
            With .DataSource
                .FirstRecord = wdDefaultFirstRecord
                .LastRecord = wdDefaultLastRecord
            End With
            .Execute Pause:=False
        End With
        
    wdDocument: FileName"Form Letters1".Activate
    
       
  ActiveDocument.ExportAsFixedFormat OutputFileName:= _
        "\\sbojsyfps001\data\Home\banimb\Data\Documents\BenAdmin\MergeTestSave\Standard Bank Jersey LimitedTest.pdf" _
        , ExportFormat:=wdExportFormatPDF, OpenAfterExport:=True, OptimizeFor:= _
        wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, _
        Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
        BitmapMissingFonts:=True, UseISO19005_1:=False
    ChangeFileOpenDirectory _
        "\\sbojsyfps001\data\Home\banimb\Data\Documents\BenAdmin\MergeTestSave\"
    
End With
    
End Sub

Anyone got any ideas?
Thanks
 
Last edited by a moderator:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I expect that should be

Code:
        wdApp.Documents("Form Letters1.docx").Activate

... or similar.
 
Upvote 0
ahh brilliant! that has got rid of the error.
However i now receive an error saying that 'ActiveDocument.ExportAsFixedFormat' is not available because no document is open.
I would of thought that activating the document would allow this command to happen?

May be just my flawed logic haha
 
Upvote 0
You need to refer to wdApp.ActiveDocument not just ActiveDocument
 
Upvote 0

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top