I am trying to create a word report & a powerpoint presentation at the same time using access. I have simplified my vb access code below so that it is just contains the part where I am having difficulty.
The code below will open a 'Doc1.doc' and 'Presentation1.ppt'. You will have to create these files and change the 'FilePath' variable if you want to trial it.
The problem that I have with it is, once it reaches the 'Stop' line, I am able to set the variable 'objWordDoc' to 'Doc1.doc', which was the active document, but I cannot set the variable 'objPresentation' to 'Presentation1.ppt' which is the active presentation (i.e. @ Stop, objWordDoc = "Doc1.doc", whilst objPresentation = ""). As far as I can tell, the powerpoint section of the code is identical to the word part of the code.
Sub OpenWord_PPoint()
Dim objWord As Object
Dim objWordDoc As Object
Dim objPPoint As Object
Dim objPresentation As Object
'Dim objPPoint As PowerPoint.Application
'Dim objPresentation As PowerPoint.Presentation
Dim FilePath As String
Dim DocumentName As Variant
Dim PresentationName As Variant
FilePath = "D:\Documents and Settings\DZU\My Documents"
'Start Microsoft Word
Set objWord = CreateObject("Word.Application")
DocumentName = "Doc1.doc"
With objWord
.Visible = True
.Documents.Open FilePath & "\" & DocumentName
Set objWordDoc = .activedocument
End With
'Start Powerpoint Presentation
Set objPPoint = CreateObject("PowerPoint.Application")
PresentationName = "Presentation1.ppt"
With objPPoint
.Visible = True
.Presentations.Open FilePath & "\" & PresentationName
Set objPresentation = .ActivePresentation
End With
Stop
End Sub
The code below will open a 'Doc1.doc' and 'Presentation1.ppt'. You will have to create these files and change the 'FilePath' variable if you want to trial it.
The problem that I have with it is, once it reaches the 'Stop' line, I am able to set the variable 'objWordDoc' to 'Doc1.doc', which was the active document, but I cannot set the variable 'objPresentation' to 'Presentation1.ppt' which is the active presentation (i.e. @ Stop, objWordDoc = "Doc1.doc", whilst objPresentation = ""). As far as I can tell, the powerpoint section of the code is identical to the word part of the code.
Sub OpenWord_PPoint()
Dim objWord As Object
Dim objWordDoc As Object
Dim objPPoint As Object
Dim objPresentation As Object
'Dim objPPoint As PowerPoint.Application
'Dim objPresentation As PowerPoint.Presentation
Dim FilePath As String
Dim DocumentName As Variant
Dim PresentationName As Variant
FilePath = "D:\Documents and Settings\DZU\My Documents"
'Start Microsoft Word
Set objWord = CreateObject("Word.Application")
DocumentName = "Doc1.doc"
With objWord
.Visible = True
.Documents.Open FilePath & "\" & DocumentName
Set objWordDoc = .activedocument
End With
'Start Powerpoint Presentation
Set objPPoint = CreateObject("PowerPoint.Application")
PresentationName = "Presentation1.ppt"
With objPPoint
.Visible = True
.Presentations.Open FilePath & "\" & PresentationName
Set objPresentation = .ActivePresentation
End With
Stop
End Sub