error code 424, object blah blah blah

S

Steff

I know this is trivial but when I try to save my newly created document, it
says error 424 - Object Required.

Here is my code...

Dim strPacName As String
Dim Count As Long
Dim NewPac As Long
strPacName = InputBox("Equipment Name", "Package Creation", , , ,
"c:\Windows\Help\Procedure Help.chm", 0)
If strPacName = "" Then End

NewPac = Shell("C:\Program Files\Microsoft Office\OFFICE11\winword.exe",
vbMaximizedFocus)

ActiveDocument.SaveAs FileName = strPacName & ".doc"

Any suggestions on why ActiveDocument does not want to save my document?
Any help would be appreciated. Thanks.
 
R

Rod Gill

Hi,

Yes. This code is running in Project and Project does not have an
ActiveDocument object, hence the error. You need to create Word application
object that does have the ActiveDocument object. To make the following code
work, in the VBE select Tools, References and add a reference to Microsoft
Word:

Sub WordTest()
Dim WordApp As Word.Application
Dim strPacName As String
Dim Count As Long
Dim NewPac As Long
strPacName = InputBox("Equipment Name", "Package Creation", , , ,
"c:\Windows\Help\Procedure Help.chm", 0)
If strPacName <> "" Then
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True
WordApp.Documents.Add
WordApp.ActiveDocument.SaveAs FileName:=strPacName & ".doc"
End If
Set WordApp = Nothing
End Sub

You can use all the Word Objects, methods and properties, but only via the
WordApp object.
--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 
S

Steff

That is perfect... thank you for the help. I never would have figured that
out on my own...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top