Running an Applcation from a Macro

slrphd

Registered User.
Local time
Today, 02:05
Joined
Jan 6, 2004
Messages
91
This must either be exceptionally easy and I am looking past the solution or it is impossible to do. I want to write a macro that opens an application using a file that I specify. My goal is to open MS-Word to work on a specific file while in the db. The db keeps track of other activities for me. So how do I pass the file name to the macro? This seems like it should be easy but it has been a tough nut for me to crack. Should I be doing this by another route?
Thanks.
 
Personally I would use VB code triggered by a command button, below is a piece of code I use.

Private Sub cmdOpenMSWord_Click()

Dim GetApplication As Object
Dim GetFile As Object

On Error Resume Next

If txtDatabase_Documentation = "No" Then

MsgBox "Database not yet documented", vbOKOnly, "Documentation"

Exit Sub

End If

If GetCountOfWindows(hWndAccessApp, "Microsoft Word") > 0 Then

MsgBox "Microsoft Word document is currently open", vbOKOnly, "File Open"

Exit Sub

End If

Set GetApplication = CreateObject("Word.Application")

On Error GoTo FILENOTFOUND

Set GetFile = GetApplication.Documents.Open("O:\SensOpen\Sens_IT\Operating_Principles\Operating_Principles_" & txtDatabase_Name & ".doc")

GetFile.Activate

GetApplication.Visible = True

Exit Sub

FILENOTFOUND:

MsgBox "Unable to find file: 'Operating_Principles_" & txtDatabase_Name & ".doc'" & vbCrLf & vbCrLf & _
"Check Database and Documentation file names correspond", vbOKOnly, "File search"

GetApplication.Quit

End Sub
 

Users who are viewing this thread

Back
Top Bottom