我想通过单击主表(sheet1)中的按钮打开文件或页面,该文件可能是excel或https:或来自sheet2中单元格(C2)的www.google.com。
我为一个按钮点击写了一个宏 - 如果它是一个excel文件它可以正常工作但如果它是一个https:它不起作用并尝试在excel中打开,因为我不知道如何区分代码。
如何通过单击按钮打开https或wwww 这是代码
Sub Macro1()
Dim xlApp As Application
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Add
xlApp.Visible = True
Dim wrkMyWorkBook As Workbook
Set wrkMyWorkBook = xlApp.Workbooks.Open(Filename:=Sheets("Sheet2").Range("C2").Value)
End Sub
在主表(sheet1)中的不同单元格中进行选择时,sheet2中的单元格c2将具有“全文/链接” 例如:sheet2中的单元格c2只有要打开的文件或页面的以下完整路径之一 H:\测试报告\ Report1.xlsm 要么 http://server:in:au:7250/Visualviwer/Analytics.jsp 要么 www.google.com
由于 KARTHIK
答案 0 :(得分:0)
当您想使用VBA打开网页时,您必须创建IE对象才能实现此目的。
Sub CallJSPPage()
Dim objIE As Object
On Error GoTo error_handler
Application.EnableEvents = True
Set objIE = CreateObject("InternetExplorer.Application")
With objIE
.Navigate " http://server:in:au:7250/Visualviwer/Analytics.jsp"
objIE.Visible = True
End With
Exit Sub
error_handler:
MsgBox ("Unexpected Error, I'm quitting.")
' objIE.Quit
Set objIE = Nothing
End Sub
您也可以通过VBA打开Chrome浏览器。但上面是你期待的那个。
希望有所帮助