|
View Full Version : error code 424, object blah blah blah
Steff 06-25-2007, 11:19 PM 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.
Rod Gill 06-26-2007, 01:40 AM 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
----------------------------------------------------------------------------------------------------
"Steff" <Steff@discussions.microsoft.com> wrote in message
news:14143341-70E9-42E1-86E7-EA4AE3AB04BF@microsoft.com...
>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.
Steff 06-26-2007, 06:10 PM That is perfect... thank you for the help. I never would have figured that
out on my own...
"Rod Gill" wrote:
> 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
>
>
> ----------------------------------------------------------------------------------------------------
>
>
> "Steff" <Steff@discussions.microsoft.com> wrote in message
> news:14143341-70E9-42E1-86E7-EA4AE3AB04BF@microsoft.com...
> >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.
>
>
>
|
|
|