Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 要应用于所有图纸的excel宏_Vba_Excel_Macros - Fatal编程技术网

Vba 要应用于所有图纸的excel宏

Vba 要应用于所有图纸的excel宏,vba,excel,macros,Vba,Excel,Macros,我有一个包含多张工作表的excel。我用下面的宏代码在一张纸上创建了一个宏。如何编辑此代码以在一次运行中应用于工作簿中的所有工作表。多谢各位 次级记分表() ' '记分表宏 " " 结束子项编辑此项以满足您的需要: Sub Theloopofloops() Dim wbk As Workbook Dim Filename As String Dim path As String Dim rCell As Range Dim rRng As Range Dim wsO As Wor

我有一个包含多张工作表的excel。我用下面的宏代码在一张纸上创建了一个宏。如何编辑此代码以在一次运行中应用于工作簿中的所有工作表。多谢各位

次级记分表() ' '记分表宏 "

"


结束子项

编辑此项以满足您的需要:

 Sub Theloopofloops()

 Dim wbk As Workbook
 Dim Filename As String
 Dim path As String
 Dim rCell As Range
 Dim rRng As Range
 Dim wsO As Worksheet
 Dim sheet As Worksheet


 path = "pathtofile(s)" & "\"
 Filename = Dir(path & "*.xl??")
 Set wsO = ThisWorkbook.Sheets("Sheet1") 'included in case you need to differentiate_
              between workbooks i.e currently opened workbook vs workbook containing code

 Do While Len(Filename) > 0
     DoEvents
     Set wbk = Workbooks.Open(path & Filename, True, True)
         For Each sheet In ActiveWorkbook.Worksheets  'this needs to be adjusted for specifiying sheets. Repeat loop for each sheet so thats on a per sheet basis
                Set rRng = sheet.Range("a1:a1000") 'OBV needs to be changed
                For Each rCell In rRng.Cells
                If rCell <> "" And rCell.Value <> vbNullString And rCell.Value <> 0 Then

                   'code that does stuff

                End If
                Next rCell
         Next sheet
     wbk.Close False
     Filename = Dir
 Loop
 End Sub
Sub-theloopoflops()
将wbk设置为工作簿
将文件名设置为字符串
将路径设置为字符串
变暗rCell As范围
暗rRng As范围
将wsO设置为工作表
将工作表设置为工作表
path=“pathtofile”和“\”
Filename=Dir(路径&“*.xl??”)
设置wsO=thiswoolk.Sheets(“Sheet1”)以防需要区分_
在工作簿之间,即当前打开的工作簿与包含代码的工作簿之间
当Len(文件名)>0时执行
多芬特
设置wbk=Workbooks.Open(路径和文件名,True,True)
对于ActiveWorkbook.Worksheets中的每个工作表,需要针对指定的工作表进行调整。对每张图纸重复循环,以便每张图纸都能重复循环
设置rRng=图纸范围(“a1:a1000”)“OBV需要更改
对于rRng.单元格中的每个rCell
如果rCell“”和rCell.Value vbNullString和rCell.Value为0,则
“代码确实有用
如果结束
下一个rCell
下一页
wbk.关闭错误
Filename=Dir
环
端接头

您可以使用类似的方法在工作表中循环。例如,此宏仅激活每个工作表并显示一个带有名称的消息框,但您只需复制粘贴要在每个工作表上运行的代码即可。重申一下@Rdster所说的,您可能需要投入一些时间来更好地组织代码,因为它非常笨重:)


你需要用谷歌搜索vba中的工作表。你能告诉我这是怎么回事吗?我不是一个开发者。谢谢你哇,录音机的代码太冗长了…请用一些清理一下。幸运的是,你不必是一名开发人员就可以用谷歌搜索。@Rdster:我想我问这个问题的原因是,我在“谷歌”上找到的结果对我来说很复杂。谢谢你的信息“幸运的是,你不必是一个开发人员就可以谷歌”谢谢你,我会给这个尝试激活表是不必要的和草率的。如果有成吨的床单呢?你想让他的剧本永远流传下去?哈哈,我只是把它作为一个例子。包括你想要的;)
 Sub Theloopofloops()

 Dim wbk As Workbook
 Dim Filename As String
 Dim path As String
 Dim rCell As Range
 Dim rRng As Range
 Dim wsO As Worksheet
 Dim sheet As Worksheet


 path = "pathtofile(s)" & "\"
 Filename = Dir(path & "*.xl??")
 Set wsO = ThisWorkbook.Sheets("Sheet1") 'included in case you need to differentiate_
              between workbooks i.e currently opened workbook vs workbook containing code

 Do While Len(Filename) > 0
     DoEvents
     Set wbk = Workbooks.Open(path & Filename, True, True)
         For Each sheet In ActiveWorkbook.Worksheets  'this needs to be adjusted for specifiying sheets. Repeat loop for each sheet so thats on a per sheet basis
                Set rRng = sheet.Range("a1:a1000") 'OBV needs to be changed
                For Each rCell In rRng.Cells
                If rCell <> "" And rCell.Value <> vbNullString And rCell.Value <> 0 Then

                   'code that does stuff

                End If
                Next rCell
         Next sheet
     wbk.Close False
     Filename = Dir
 Loop
 End Sub
Sub WorksheetLoop()

Dim Count1 As Integer
Dim i As Integer

'Set Count1 equal to the number of worksheets in the active workbook.

Count1 = ActiveWorkbook.Worksheets.Count

For i = 1 To Count1

    Worksheets(i).Activate

    MsgBox ActiveWorkbook.Worksheets(i).Name

Next

End Sub