看板 Office 關於我們 聯絡資訊
因為要用外部資料連結抓一些資料進來excel 但每天日期都會變,巨集有辦法設定好日期 然後自動修改外部資料連結的網址日期嗎?? 例如: 外部資料連結的網址如下 A = Cells(1, 2).Value '抓取儲存格B1的代號 B = Cells(1, 4).Value C = Cells(1, 6).Value Range("A3:F26").Select '顯示的範圍從A3到F26 Selection.ClearContents '清除A3到F26 With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://ptt.cc"& A_B_C & "_D.djhtm", Destination:= _ 我黃色這段語法錯誤,不知如何修改?? 簡單的覆製、貼上巨集我會,但突然沒有idea如何去設定日期來製作巨集 可以給我一些idea嗎?? 3Q -- 一個年輕人問一個老人:「智慧從哪裡來?」 老人回答說:「精確的判斷力。」 年輕人又接著問老人:「那麼精確的判斷力從哪裡來?」 老人又接著回答說:「靠經驗。」 年輕人再問老人:「經驗哪裡來?」 老人說:「錯誤的判斷力。」 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.33.66.62 ※ 文章網址: http://www.ptt.cc/bbs/Office/M.1396543089.A.317.html ※ 編輯: a777starmy (114.33.66.62), 04/04/2014 03:09:42
soyoso:可能是with的問題,with是簡化陳述式為目的 04/04 12:09
soyoso:可否提供檔案 04/04 12:09
a777starmy:資料是公司內部資料檔案,可能不方便 >< 04/04 13:06
I4Lione:有 With 沒有 End With? 04/04 13:10
soyoso:那可以只貼巨集內容從sub..end sub 04/04 13:19
你看一下 Dim stocknumber As String '定義股票代號為字串 Dim startday As String Dim endday As String stocknumber = Cells(1, 2).Value '抓取儲存格B1的代號 startday = Cells(1, 4).Value endday = Cells(1, 6).Value Range("A3:F26").Select '顯示的範圍從A3到F26 Selection.ClearContents '清除A3到F26 With ActiveSheet.QueryTables.Add(Connection:= _ "URL;http://money.hinet.net/z/z0/z00/z00a_" & stocknumber _ & startday _ & endday _D.djhtm", Destination:= _ Range("$A$3")) .Name = "z00a_2498_2012-1-1.djhtm" .FieldNames = True .RowNumbers = False .FillAdjacentFormulas = False .PreserveFormatting = True .RefreshOnFileOpen = False .BackgroundQuery = True .RefreshStyle = xlInsertDeleteCells .SavePassword = False .SaveData = True .AdjustColumnWidth = False .RefreshPeriod = 0 .WebSelectionType = xlSpecifiedTables .WebFormatting = xlWebFormattingNone .WebTables = "2" .WebPreFormattedTextToColumns = True .WebConsecutiveDelimitersAsOne = True .WebSingleBlockTextImport = False .WebDisableDateRecognition = False .WebDisableRedirections = False .Refresh BackgroundQuery:=False End With ※ 編輯: a777starmy (114.33.66.62), 04/04/2014 13:49:18
soyoso:http://goo.gl/3Gtzcp 試試 04/04 14:41