Excel 2010 VBA函数在计算后粘贴为值
我在Excel2010中使用这个网页抓取VBA代码来删除网页标题。我希望它在代码运行后将标题粘贴为值 这是我的密码:Excel 2010 VBA函数在计算后粘贴为值,excel,excel-2010,vba,Excel,Excel 2010,Vba,我在Excel2010中使用这个网页抓取VBA代码来删除网页标题。我希望它在代码运行后将标题粘贴为值 这是我的密码: Function GetTitleFromURL(sURL As String) Dim wb As Object Dim doc As Object Set wb = CreateObject("InternetExplorer.Application") wb.Navigate sURL While wb.Busy DoEvents Wend GetTitle
Function GetTitleFromURL(sURL As String)
Dim wb As Object
Dim doc As Object
Set wb = CreateObject("InternetExplorer.Application")
wb.Navigate sURL
While wb.Busy
DoEvents
Wend
GetTitleFromURL = wb.Document.Title
wb.Quit
Set wb = Nothing
'trying to paste as value after get title
'Application.CutCopyMode = False
' Selection.Copy
' Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
' :=False, Transpose:=False
End Function
谢谢你的帮助 这样的东西可能合适吗
Sub GetTitleFromURL()
Dim source_wb As Object
Dim target_wb As Object
Dim target_sheet As Object
Dim title As String
Dim sURL As String
Set target_wb = ActiveWorkbook
Set target_sheet = target_wb.ActiveSheet
sURL = target_sheet.Range("A1").Value
Set source_wb = CreateObject("InternetExplorer.Application")
source_wb.Navigate sURL
While source_wb.Busy
DoEvents
Wend
title = source_wb.Document.title
source_wb.Quit
target_sheet.Range("B1").Value = title
Set source_wb = Nothing
Set target_sheet = Nothing
Set target_wb = Nothing
End Sub
你是不是想把它当作一个UDF?如果是这样,您将无法以这种方式在XL上执行操作。我不知道,UDF是什么?UDF=
用户定义函数
,也就是说,从工作表上的单元格调用VBA函数,如下所示=GetTitleFromURL(“www.MyUrl.com”)
。如果您是从其他VBA代码调用它,那么它是可以的(但不是为此而精心设计的)。