2013-01-04 4 views
0

Excel 웹 페이지에서 VBA 코드를 긁어 내 웹 페이지에서 제목을 가져옵니다. 코드가 실행 된 후 제목으로 값을 붙여 넣기를 원합니다. 당신의 도움에 대한Excel 2010 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 

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 

감사 :

여기 내 코드입니다!

+0

UDF와 같이 실행 하시겠습니까? 그렇다면 XL에서 작업을 수행 할 수 없습니다. –

+0

저는 UDF가 무엇인지 모르겠습니다. –

+0

워크 시트의 셀에서 VBA 함수를 호출하는 곳의 UDF ='User Defined Function '입니다 (이 경우 = GetTitleFromURL ("www.MyUrl.com")'). 다른 VBA 코드에서 호출하면 OK입니다 (그러나 잘 설계된 것은 아닙니다). –

답변

0

아마도 이와 비슷한 것이 적합할까요?

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 
+0

감사합니다! 이것은 완벽하게 작동합니다. –