2014-05-19 3 views
1

vba에서 다음 코드를 사용하여 증권 거래소의 일일 가격을 다운로드하고 싶습니다. 코드가 작동하지만 시트가 가격표를 얻은 해당 날짜로 바꿀 수있는 것 같습니다.웹에서 데이터를 가져온 후 엑셀로 이름을 바꾼 워크 시트 받기

Dim DownloadDay As Date 

DownloadDay = #3/4/2014# 

Do While DownloadDay < #4/4/2014# 

ActiveWorkbook.Worksheets.Add 

Call website(Format(DownloadDay, "YYYYMMDD")) 

'INCREMENT THE DAY 

Sheets.Add.Name = "DownloadDay" 

DownloadDay = DownloadDay + 1 



    Loop 

End Sub 

Sub website(sDate As String) 

With ActiveSheet.QueryTables.Add(Connection:= _ 
"URL;http://live.mystocks.co.ke/price_list/" & DownloadDay & "/", Destination:=Range("$A$1")) 


.Name = DownloadDay 
'To rename each work sheet with the corresponding day' 


.FieldNames = True 

.RowNumbers = False 

.FillAdjacentFormulas = False 

.PreserveFormatting = True 

.RefreshOnFileOpen = False 

.BackgroundQuery = True 
.RefreshStyle = xlInsertDeleteCells 
.SavePassword = False 
.SaveData = True 
.AdjustColumnWidth = True 
.RefreshPeriod = 0 
.WebSelectionType = xlTables 
.WebFormatting = xlWebFormattingNone 
.WebPreFormattedTextToColumns = True 
.WebConsecutiveDelimitersAsOne = True 
.WebSingleBlockTextImport = False 
.WebDisableDateRecognition = False 
.WebDisableRedirections = False 
.Refresh BackgroundQuery:=False 


End With 

End Sub 

답변

1

VBA의이 줄은 워크 시트의 이름을 설정합니다 : 당신은 사용할 수 없습니다

Sheets("Sheet2").Name = "NewName" 

은 "/"하지만 이름의 문자, 변수는 날짜로 설정되지 않은 끈.

시도해보십시오.

.name = CSTR(FORMAT(DownloadDay,"YYYYMMMDD")) 
관련 문제