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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening any File 1

Status
Not open for further replies.

centaur21

Technical User
Oct 3, 2006
10
US
Is there an easy way to open any type of file using VBA? I have used Process.Start(FullFilename)in VB.NET, but that doesn't work with VBA. I would appreciate any help you could provide. Thanks.
 
Could you expand that a little? What do you mean by "any" file? VBA is Visual Basic for Applications, and those applications are those that are VBA compliant.

What do you mean by "open", as well. An .exe file is an "any" file. Do you mean execute an executable? Say use VBA to open...oh, I don't know....QuickTimePlayer.Exe?

SHELL will execute an .exe, and this can be done with VBA.

A .DLL is an "any" file. Do you mean "open" a DLL?

You question is too fuzzy.



Gerry
My paintings and sculpture
 
What I meant was to be able to open a .pdf, .doc, .txt, .xls, .pps etc....., file from within a VBA windows form. I am not able to download VB.NET Express Edition at work so I am trying to use Excel VBA instead. I know how to do it using VB.NET, but as said before, I am unable to download it to my computer at work. Therefore, I am looking for a way to do the same things using VBA, which from what I'm seeing, the code needed is different from VB.NET.
 
The code is very different to VB.NET.

I would use ShellExecute() for your problem, a quick search on this forum finds you lots of examples, including thread707-686779.

Hope this helps

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I haven't had a chance to, but I will PHV. I was just explaining to fumei what I meant by my first post. Thanks for the information.
 
Sorry PHV, hadn't refreshed my browser before I posted [blush]

HarleyQuinn
---------------------------------
Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
I still think you need to clarify precisely what you are doing.

Say you are in Excel, and you want to open a .DOC (Word) file.

You can:

A) use a SHELL command to execute winword.exe and the file

B) use VBA to make an explicit instance of Word and have that instance of Word open the file.

In both cases the file is opened. Which way you use depends on what you are wanting to do with the file.

Say you are in Excel and you want to open a .TXT file.

Are you wanting to import ("open") the .TXT file into EXCEL?

Are you wanting to open the .TXT file in some other application? Notepad? Word?

Gerry
My paintings and sculpture
 
Where I work, we keep all of the files on a server. These files are in many different directories. I want to have a one stop area to go to to pull up whatever document, pdf, etc.. that I want from within the windows form. For example, I may be working on several projects and there are many different documents that I may need to refer to that are specific to that project. I may use a combobox, which is specific to the project I am working on at the time, and have a list of particular documents I may need to look at in the list in the combobox. I would create a combobox for each project I am working on. And again, I would prefer to do this in VB.NET b/c I have done it before, but I am unable to install VB.NET Express Edition on my computer at work; and as I go alone, I may need to update the combobox list and would like to do it right then and there at work. The only way I see doing this is using VBA.

I hope this clears up what I am trying to do. I haven't tried the above suggestion yet, but I will later.
 
I do this as a hyperlink on a drawn object.

Code:
ActiveSheet.Shapes("AutoShape 1").Select

ActiveSheet.Hyperlinks.Add 

Anchor:=Selection.ShapeRange.Item(1), _ Address:=stringvariable 

   ActiveSheet.Shapes("AutoShape 1").Hyperlink.Follow

it is the "Follow" that does it. Can't seem to get it to do it from a cell so I have a few drawing objects (shapes) off to the right but maybe they could be visible = false.
 
Code:
ActiveSheet.Hyperlinks.Add _ Anchor:=Selection.ShapeRange.Item(1), Address:= _
Address:=stringvariable

is all one line - the "Add" needs attributes.
 
cresbydotcom, your suggestion is for Exel VBA only, mine is for ANY VBA ...
 
Alternatively, should this be in VBA at all? Wouldn't a Windows folder with shorcuts be more practical?

_________________
Bob Rashkin
 
Yes that would be more practical, but I am using this as a learning experience more than for it to be practical. I, obviously, have not done much in VBA and would like to learn more about it.

I would appreciate suggestions on any REALLY GOOD VBA books out there. Thank you!
 
Microsoft does not directly support any tutorials on VBA. They also offer no certification path for VBA.

You still have not answered my questions.

A userform that collects file names from specified folders and puts the names into a combobox is quite do-able. Selecting one from the combobox and opening it from the userform is also quite do-able.

Shrug....but again, say it is a .TXT file....what do you want to do with it?

Since you don't seem to want to actually specify things, I suggest you browse through here. There are a number of threads on populating comboboxes with filenames. Also a number on how to open files.

Good luck.

Gerry
My paintings and sculpture
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top