Auto-Fill Word Document opens word, but doesnt do anything

samlonergan

Board Regular
Joined
May 5, 2014
Messages
70
Hey guys,

I'm completely stuck. I've used this macro to autofill many Word Documents, and they all work perfectly except for this one. When I run it, it opens word, but just sits there empty (i.e. no document open).

I cannot for the life of me figure it out (although my head is swimming with code at the moment, so It could be something obvious.)

Code:
Sub QualPlan()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Dim appWord As Word.Application
Dim objWord As Word.Application
Dim CatJA As Excel.Range
Dim CatJB As Excel.Range
Dim Current As String
Current = CurDir$()
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
Set appWord = GetObject(, "Word.Application")
Set myDoc = wdApp.Documents.Open(Filename:=ActiveWorkbook.Path & "\SECTION 3 - Project Specific Quality Mgt. Plan & ITP's\Project Specific Quality Management Plan.docm")
Set CatJA = Sheets("Sheet1").Range("C12")
Set CatJB = Sheets("Sheet1").Range("C11")

With myDoc.Bookmarks
.Item("QualProjectName").Range.InsertAfter CatJA
.Item("QualClientName").Range.InsertAfter CatJB
 
End With

errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
Set appWord = Nothing
ActiveDocument.Close savechanges:=True
objWord.Application.Quit wdDoNotSaveChanges
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I've used this macro to autofill many Word Documents, and they all work perfectly except for this one.
That makes no sense at all. You've posted one macro and it's only coded to work with one document:
Project Specific Quality Management Plan.docm

Does that document exist there? Are you sure it's a docm file? Does it have macros of its own? Why do you have:
• Dim mywdRange As Word.Range
• Dim appWord As Word.Application
• Dim objWord As Word.Application
• Set appWord = GetObject(, "Word.Application")
• Set mywdRange = Nothing
• Set appWord = Nothing
There's no indication any of that code does anything relevant to the rest of what you've posted. Instead of:
ActiveDocument.Close savechanges:=True
you should have:
myDoc.Close savechanges:=True
but, in any event, since you have that line, when the processing has finished all you'll have is an empty Word window - exactly what you're describing.
 
Upvote 0
Thanks Paul,

I ended up figuring it all out. I redid the code and it now works. Thanks very much for the help all!
 
Upvote 0

Forum statistics

Threads
1,225,681
Messages
6,186,411
Members
453,352
Latest member
OrionF

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