Command Buttton to Open InfoPath File

A

Art Caragh

I am using Word 2003. I have added a command button to a file and I would
like to use this button to open an InfoPath document.
I am not a developer and normally I would copy and paste Macros.

I would be grateful for some help

Regards

ArtCaragh
 
S

Shauna Kelly

Hi Art

You can get very sophisticated with something like this. For example, if the
file does not open, you can give the user different messages depending on
the reason the file didn't open (eg the file didn't exist, InfoPath wasn't
installed), but this should get you going.

STEP 1: At the top of your module, before any other Subs or Functions, paste
the following:

Private Declare Function ShellExecute Lib "shell32.dll" _
Alias "ShellExecuteA" (ByVal HWnd As Long, _
ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long



STEP 2: Now, paste this anywhere in your module:

Sub OpenMyInfoPathFile()

Dim lngResult As Long
Dim sPFN As String

'Change the following to your file and path name
sPFN = "D:\D\test\Form1.xml"

lngResult = ShellExecute(0&, "open", sPFN, vbNullString, vbNullString,
vbNormalFocus)
If lngResult > 32 Then
'cool!
Else
MsgBox "Could not open this InfoPath file"
End If


End Sub


STEP 3: Finally, attach the OpenMyInfoPathFile to your button.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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