无法在自定义文件夹中保存和关闭新创建的工作簿
Can't save and close a newly created workbook in a customized folder
我创建了一个宏,它能够从 Torrent 站点解析一些电影名称。
我现在要做的是(我的脚本已经可以满足前三个要求,除了第四个):
1. Create a folder in my desktop
2. Create a new workbook after the name of the `Genre`
3. write the data in that new workbook
4. Save and close the data-ridden workbook in the newly created folder
这是我目前的尝试:
Sub CreateAndSaveWorbook()
Const link = "https://yts.am/browse-movies/0/all/action/0/latest"
Dim Http As New XMLHTTP60, Html As New HTMLDocument, genre$
Dim post As HTMLDivElement, wb As Workbook
Dim daddr$, fdObj As Object
daddr = Environ("USERPROFILE") & "\Desktop\Test\"
Set fdObj = CreateObject("Scripting.FileSystemObject")
If Not fdObj.FolderExists(daddr) Then fdObj.CreateFolder (daddr)
With Http
.Open "GET", link, False
.send
Html.body.innerHTML = .responseText
End With
genre = Html.querySelector("select[name='genre'] option[value='action']").innerText
Set wb = Workbooks.Add
wb.SaveAs daddr & genre & ".xlsx"
For Each post In Html.getElementsByClassName("browse-movie-bottom")
R = R + 1: wb.Sheets(1).Cells(R, 1) = post.getElementsByClassName("browse-movie-title")(0).innerText
Next post
End Sub
How can I save and close a newly created workbook in a customized folder?
这是你的答案:) :将 wb.saveAs
更改为 wb.Close true, daddr & genre & ".xlsx"
我创建了一个宏,它能够从 Torrent 站点解析一些电影名称。
我现在要做的是(我的脚本已经可以满足前三个要求,除了第四个):
1. Create a folder in my desktop
2. Create a new workbook after the name of the `Genre`
3. write the data in that new workbook
4. Save and close the data-ridden workbook in the newly created folder
这是我目前的尝试:
Sub CreateAndSaveWorbook()
Const link = "https://yts.am/browse-movies/0/all/action/0/latest"
Dim Http As New XMLHTTP60, Html As New HTMLDocument, genre$
Dim post As HTMLDivElement, wb As Workbook
Dim daddr$, fdObj As Object
daddr = Environ("USERPROFILE") & "\Desktop\Test\"
Set fdObj = CreateObject("Scripting.FileSystemObject")
If Not fdObj.FolderExists(daddr) Then fdObj.CreateFolder (daddr)
With Http
.Open "GET", link, False
.send
Html.body.innerHTML = .responseText
End With
genre = Html.querySelector("select[name='genre'] option[value='action']").innerText
Set wb = Workbooks.Add
wb.SaveAs daddr & genre & ".xlsx"
For Each post In Html.getElementsByClassName("browse-movie-bottom")
R = R + 1: wb.Sheets(1).Cells(R, 1) = post.getElementsByClassName("browse-movie-title")(0).innerText
Next post
End Sub
How can I save and close a newly created workbook in a customized folder?
这是你的答案:) :将 wb.saveAs
更改为 wb.Close true, daddr & genre & ".xlsx"