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

Open HMTL file in excel

Status
Not open for further replies.

NHSSAS

Programmer
Mar 19, 2010
4
GB
Hi,

I want to open a html file that I have created in excel (i.e. so it is now in Excel format and not html). I can use 'open with' and select excel as the application to open it, and this works. However, I want to be able to do this in VBA so it automatically opens the html file in excel (I will be doing this for a lot of html files). I have the following code to get to the point of bringing up the "open with" dailogue box, but I want to automatically select excel. Any ideas?

Sub OpenHow()
' String for the file path:
Dim szFileToOpen As String
szFileToOpen = "P:\sasreport-1.1parta.html"


' String for RunDll:
Dim szOpenWith As String
szOpenWith = "rundll32.exe shell32.dll,OpenAs_RunDLL " & szFileToOpen


' Variable for the shell:
Dim vRun As Variant
vRun = Shell(szOpenWith, vbMaximizedFocus)
End Sub
 
Your file is in html format. Try, if you need to open from non-excel host application or second excel instance:
Code:
Dim xlApp As Object
Dim szFileToOpen As String
szFileToOpen = "P:\sasreport-1.1parta.html"
Set o = New Excel.Application
o.Visible = True
o.Workbooks.Open szFileToOpen
In excel (the same instance):
Code:
Dim szFileToOpen As String
szFileToOpen = "P:\sasreport-1.1parta.html"
Workbooks.Open szFileToOpen


combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top