Jump to content

Opening a Template file from Excel VBA


Recommended Posts

Posted (edited)

I have been trying to open a template from Excell using VBA code and finally got the code below to work for me.:D

 

Only problem is that it opens the template file twice.:(

 

Can anyone see why it woulf be doing that?

 

Cheers

Bob

 

Option Explicit

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

Function OpenAnyFile(FileToOpen As String)
    
   Call ShellExecute(0, "Open", FileToOpen & vbNullString, _
   vbNullString, vbNullString, 1)
    
End Function

Sub Example()
    
   Call OpenAnyFile("I:\Support\Drafting\Drawing Templates\Skid.dwt")
    
End Sub

Edited by Bobkat
Oops, that better?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...