全部 - 我正在尋找一個循環,我可以根據它在循環中運行的值更改文件名和文件夾位置。例如,如果我正在從單元格G2:G7運行宏,當進程從G2移動到G3時,我希望文件名和文件夾位置根據某個參考表(詳情請查看圖像)進行更改。實際上,我希望文件名和文件夾名稱是查找基金類型。Vlookup在循環過程中更改保存文件名VBA
Public Sub Get_File()
Dim sFiletype As String
Dim sFilename As String 'Save the file as this name, if "" then default
Dim sFolder As String 'Save to this folder, if "" then default
Dim bReplace As Boolean 'To replace the existing file or not
Dim sURL As String 'The URL to the location to extract information
Dim cell, Rng As Range
Dim sheet As Worksheet
'Initialize variables
Set Rng = Range("I2:I10")
Set sheet = ActiveWorkbook.Sheets("Macro_Button")
For Each cell In Rng
If cell <> "" Then
sFiletype = cell.Value
sFilename = sFiletype & "_" & Format(Date, "mmddyyyy")
sFolder = Application.WorksheetFunction.VLookup(sFiletype, sheet.Range("G2:J10"), 4, False)
bReplace = True
sURL = "www.preqin.com"
'Download using the desired approach, XMLHTTP/IE
Call Download_Use_IE(sURL, sFilename, sFolder, bReplace)
Else
Exit Sub
End If
Next
End Sub
感謝大家的意見!
http://i.stack.imgur.com/M6GSs.png
您能否將此代碼縮小到您遇到問題的確切區域? SO鼓勵[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve),但也建議指出相關部分。 – Parfait
http://stackoverflow.com/users/1422451/parfait - 上面是我正在處理,但這似乎並沒有工作。我目前卡在vlookup行,並不斷獲得運行時錯誤'1004'無法獲得工作表功能類的vlookup屬性 –