Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VB procedures to open files

Status
Not open for further replies.

grierfield

Technical User
Dec 18, 2002
55
US

Private Sub CommandButton1_Click()



ChDir "H:\PDOXSHAR\Monthly Reports 2009\MDRO rates Calc"

Workbooks.Open Filename:= _

"H:\PDOXSHAR\Monthly Reports 2009\MDRO rates Calc\NOSOCOMIAL RATES KHD & PET 08.xls"





End Sub

The above procedure opens an Excel (.xls) file





How would I open a PowerPoint file in the same directory path – the only difference is the file name has a .ppt extension?

Thanks
 

What you wrote opens an Excel file because you are .... in Excel.

If you want to open a file with default file association:
Code:
Option Explicit

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
Then call it like this:
Code:
ShellExecute(0&, "open", sFileName, vbNullString, vbNullString, vbNormalFocus)

Or, start any file;
Code:
Public Sub OpenDocument(strDocPath As String)

Dim G As Long
G = Shell("RUNDLL32.EXE URL.DLL,FileProtocolHandler " & strDocPath, vbNormalFocus)
    
End Sub



Have fun.

---- Andy
 



Do you ONLY want to open this application and nothing else to PowerPoint with respect to your code.

Or do you ALSO want to use VBA to manipulate the PowerPoint objects?

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The problem is that personel in the office have difficulty locating and opening files - i would like to setup of Vb procedures with the file "description captions" so when people click them it opens the file for them

Thanks
 



Set up a DeskTop Folder with shortcuts to these files. No need to write code!

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Set up a DeskTop Folder with shortcuts to these files. No need to write code!


true - but with little click events all on a single sheet - they could keep that sheet open and minimized and just click to open a file when needed - that would be neater and easier.
 



But then your user must have THAT workbook open. Extra overhead like 20+ MB of memory for Excel to be open, if it does not need to be otherwise.

But if you think that's easier for you (cuz ALL programs need maintenance, eventually) and them, knock yourself out! You have yourself a solution. ;-)

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Set up a DeskTop Folder with shortcuts to these files. No need to write code!


plus knowing how to write such codes is a plus for me
 



That may be so, and I'd strongly encourage you to code it and make it work, if your have the time and inclination. You never know when you might need to pull that one out of the bag at some time in the future. I've done similar adventursome excurstions that I never used for months or even years.

But is that a good reason to use it in THIS instance?

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
But is that a good reason to use it in THIS instance?

i dont know - its just a thought i have - plus to do shortcuts - would have to go to everyone's PC. we have users 20 miles away loging in and sharing the same files - if i had one page with all the click events that all the users could pull-up and click on a caption to open a file - that just seem cool.

the problem is i am a neophite when it comes to programming - so i need to be shepearded thru this.
 


You'll get some good help, I'm sure.

Skip,
[sup][glasses]Don't let the Diatribe...
talk you to death![tongue][/sup][sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
plus to do shortcuts - would have to go to everyone's PC"

You can set up a link to the links folder (the links folder could be on a share). There really is no need to complicate this by writing code.

Best to implement the good solution yourself so someone else can't suggest it and take the credit!

Paul
VBA, C#, Delphi
 
You could create an Excel Toolbar, create buttons like you would for macros but instead of assigning a macro use hyperlink to the file you want it to open.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top