Jaymond Flurrie
Well-known Member
- Joined
- Sep 22, 2008
- Messages
- 921
- Office Version
- 365
- Platform
- Windows
I'm making a program that creates some charts, pastes them to Word and loops that around a certain number of times, for example 40 times. I got it already to work, but then I realized that it's pretty slow to create the Word application and document each time from scratch, so I decided to do that once, delete everything from the document, paste the charts to Word save the document and loop that process instead.
So now I got to create that function. Here's the important part I have:
And yes, I do have the references set, because it works without this function (ie. when I create a new Word application each time)
I clearly have some syntax problem here about returning the object, since it gives me "invalid use of syntax". What is it and how do I fix it?
SOLUTION: The last linee misses a "SET" ie. it should be
Set CreateChartDoc = DocWD
So now I got to create that function. Here's the important part I have:
Code:
Sub ChartsMain()
Dim DocWD As Word.Document
Set DocWD = CreateChartDoc
End Sub
Code:
Function CreateChartDoc() As Word.Document
Dim appWD As Word.Application 'Word application
Dim DocWD As Word.Document 'Word document
'Open a hidden Word instance
Set appWD = CreateObject("Word.Application")
appWD.Visible = False
'Create a new document
Set DocWD = appWD.Documents.Add
'Return a Word document
CreateChartDoc = DocWD
End Function
And yes, I do have the references set, because it works without this function (ie. when I create a new Word application each time)
I clearly have some syntax problem here about returning the object, since it gives me "invalid use of syntax". What is it and how do I fix it?
SOLUTION: The last linee misses a "SET" ie. it should be
Set CreateChartDoc = DocWD
Last edited: