위에 분께서 훌륭하게 만들어주셨군요. 해당 매크로가 원하는데로 작동하지 않는 이유는, 첫번째로, 주소 부분에서 from_year앞에 &가 빠졌습니다. 아래 빨간 색의 &를 기존 소스에서 추가해주셔야합니다. "URL;http://fund.finance.daum.net/zeroin/app/Finfo_gijunga.asp?FCD=hNC4B3Tw7Y02ocq6E0oCmBI26rvHp4J7Lsf1&FCD1=&subMenuIdx=21&" _ & "from_year=" & year - 1 & "&from_month=" & month & "&from_day=" & day & "&" _ & "to_year=" & year & "&to_month=" & month & "&to_day=" & day _
두번째로, 월과 일의 데이터 포멧이 틀려서입니다. 1자리 월도 2자리로 표현되어야하지요. 4월이 아니고 04월입니다. 포멧함수를 사용해서 수정할 수 있습니다. year = Format(Cells(5, 4), "0000") month = Format(Cells(5, 5), "00") day = Format(Cells(5, 6), "00") 이때, 앞에서 integer로 선언한 것을 string으로 변경해줘야하구요. Dim year As String Dim month As String Dim day As String
긁어서 바로 적용할 수 있는 수정된 매크로는 아래와 같습니다. Sub 펀드기준가조회2() ' ' 펀드기준가조회 Macro '
'날짜설정 Dim year As String Dim month As String Dim day As String
year = Format(Cells(5, 4), "0000") month = Format(Cells(5, 5), "00") day = Format(Cells(5, 6), "00")
'이전내용을 지웁니다 Range("a6:h300").Select Selection.Delete Shift:=xlToLeft
With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://fund.finance.daum.net/zeroin/app/Finfo_gijunga.asp?FCD=hNC4B3Tw7Y02ocq6E0oCmBI26rvHp4J7Lsf1&FCD1=&subMenuIdx=21&" _ & "from_year=" & year - 1 & "&from_month=" & month & "&from_day=" & day & "&" _ & "to_year=" & year & "&to_month=" & month & "&to_day=" & day _ , Destination:=Range("A6")) .Name = _ "미래에셋BRICs업종대표주식형자1C-A=FCD=hNC4B3Tw7Y02ocq6E0oCmBI26rvHp4J7Lsf1&FCD1=&subMenuIdx=" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlOverwriteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = True .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "12" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With End Sub
참고로.. 별도의 날짜 지정 없이, 오늘 날짜를 기준으로 1년 단위로 검색하시려면 변수값을 아래처럼 지정해주면 됩니다. year = Format(Date, "yyyy") month = Format(Date, "mm") day = Format(Date, "dd")
역기서 Date는 오늘 날짜를 의미합니다.
|