[求助]谁能帮我修改一下,这个宏?

yzd1109 2007-05-08 03:07:51
我自己录了一个宏,如下:

Sub yzs2()
'
' yzs2 Macro
' 宏由 User 录制,时间: 2005-5-7
'
' 快捷键: Ctrl+z
'
Cells.Select
Selection.ClearContents
Selection.QueryTable.Delete
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;file:///D:/新建文件夹%20(2)/330.htm", Destination:=Range("A1"))
.Name = "338"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
我在D盘里有很多按顺序排列的“D:/新建文件夹%20(2)/339.htm”下载来的网页文件(宏代码中的黑体),330.htm、331.htm~~~

我的问题是,如何在每次使用这个宏时,网页名称自动加一?

     如330.htm,用一次宏后变为“D:/新建文件夹%20(2)/331.htm”

          用二次宏后变为“D:/新建文件夹%20(2)/332.htm”

          用三次宏后变为“D:/新建文件夹%20(2)/333.htm”

          以此类推。

希望大家多多指点。
...全文
227 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
XYX_YE 2007-05-13
  • 打赏
  • 举报
回复
dim s as string'把这一行移到代码页的最顶部
Sub yzs2()
'
' yzs2 Macro
' 宏由 User 录制,时间: 2005-5-7
'
' 快捷键: Ctrl+z
'
dim addr as string
if s="" then
s=inputbox("请输入你想开始的数字:")'如填入339
else
s=s+1
end if
addr="URL;file:///D:/新建文件夹%20(2)/" & s & ".htm"
Cells.Select
Selection.ClearContents
Selection.QueryTable.Delete
Range("A1").Select
With ActiveSheet.QueryTables.Add(Connection:= addr, Destination:=Range("A1"))
.Name = "338"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
祝你好运
yzd1109 2007-05-10
  • 打赏
  • 举报
回复
首先,谢谢Yiqun_Zhao的回复。
但是我不会用VBA,那该如何“使用For Each遍历该文件夹,依次读取文件”。最好能在我的宏中修改。
蓝帆·雨轩 2007-05-09
  • 打赏
  • 举报
回复
您使用For Each遍历该文件夹,依次读取文件即可。
smallcrocodile 2007-05-09
  • 打赏
  • 举报
回复
不熟

6,210

社区成员

发帖
与我相关
我的任务
社区描述
Microsoft Office应用
社区管理员
  • Microsoft Office应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧