My Macro quit working

counihan3

Active Member
Joined
Mar 9, 2007
Messages
458
I have been using this macro for a while now and now it will not work. I think it has something to do with and update that I have installed but I am not sure. I keep getting invalid syntax error. At Set oWord = GetObject(, "Word.Application") I have no idea what is going on any help would be great.

Code:
Dim oWord As Word.Application
Dim WordWasNotRunning As Boolean
Dim oDoc As Word.Document
Dim myDialog As Word.Dialog
Dim UserButton As Long

On Error Resume Next

Set oWord = GetObject(, "Word.Application")
If Err Then
    Set oWord = New Word.Application
    WordWasNotRunning = True
End If

On Error GoTo Err_Handler

oWord.Visible = True
oWord.Activate
Set oDoc = oWord.Documents.Add("C:\Macros\Letter1 (Macro).dot")

    oDoc.Bookmarks("Line1").Range.InsertBefore rname
    oDoc.Bookmarks("Line2").Range.InsertBefore madd1
    oDoc.Bookmarks("Line3").Range.InsertBefore madd2
    oDoc.Bookmarks("Line5").Range.InsertBefore padd1 & " " & padd2
    oDoc.Bookmarks("Line6").Range.InsertBefore npmt
    oDoc.Bookmarks("Line7").Range.InsertBefore nduedate
    oDoc.Bookmarks("Line10").Range.InsertBefore effdate
    oDoc.Bookmarks("Line13").Range.InsertBefore remterm
    oDoc.Bookmarks("Line14").Range.InsertBefore matdate
    oDoc.Bookmarks("Line15").Range.InsertBefore effdate
    oDoc.Bookmarks("Line16").Range.InsertBefore capint
    oDoc.Bookmarks("Line17").Range.InsertBefore effdate
    oDoc.Bookmarks("Line18").Range.InsertBefore capesc
    oDoc.Bookmarks("Line19").Range.InsertBefore npmt
    oDoc.Bookmarks("Line20").Range.InsertBefore nduedate
    oDoc.Bookmarks("Line22").Range.InsertBefore mextn
    oDoc.Bookmarks("Line23").Range.InsertBefore epmt
    oDoc.Bookmarks("Line24").Range.InsertBefore workby
    oDoc.Bookmarks("Line25").Range.InsertBefore workby

With oDoc
'    .PrintOut
    .SaveAs "C:\Letters\" & clsavename
'    .Close
End With
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
2003, I have got it working for know though I changed Set oWord = GetObject(, "Word.Application") to Set oWord = CreateObject("Word.Application") hopefully it won't break agian.
 
Upvote 0
If that fixed it then it probably means there was no open instance of Word to Get.

PS Couldn't you use Word mail merge for this?
 
Upvote 0

Forum statistics

Threads
1,224,506
Messages
6,179,158
Members
452,892
Latest member
yadavagiri

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