Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.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 从隐藏图纸复制范围_Vba_Excel - Fatal编程技术网

Vba 从隐藏图纸复制范围

Vba 从隐藏图纸复制范围,vba,excel,Vba,Excel,我有一个vba代码来复制和粘贴文件夹中多个excel文件中的一系列数据。但包含数据的工作表是隐藏的。我需要修改代码以复制隐藏的图纸范围 Sub Import_to_Master() Dim sFolder As String Dim sFile As String Dim wbD As Workbook, wbS As Workbook Application.ScreenUpdating = False Set wbS = ThisWorkbook sFolder = wbS.Pa

我有一个vba代码来复制和粘贴文件夹中多个excel文件中的一系列数据。但包含数据的工作表是隐藏的。我需要修改代码以复制隐藏的图纸范围

Sub Import_to_Master() 
Dim sFolder As String 
Dim sFile As String 
Dim wbD As Workbook, wbS As Workbook

 Application.ScreenUpdating = False Set wbS = ThisWorkbook sFolder =
 wbS.Path & "\"

 sFile = Dir(sFolder) Do While sFile <> ""

 If sFile <> wbS.Name Then Set wbD = Workbooks.Open(sFolder & sFile)
 'open the file; add condition to

 ' >>>>>> Adapt this part wbD.Sheets("data").Range("A3:BD3").Copy
 wbS.Activate Sheets("data scorecards").Range("A" &
 Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
 Application.CutCopyMode = False ' >>>>>> wbD.Close savechanges:=True
 'close without saving End If

 sFile = Dir 'next file Loop Application.ScreenUpdating = True

End Sub
Sub Import_to_Master()
作为字符串的Dim-sFolder
将文件设置为字符串
将wbD设置为工作簿,将wbS设置为工作簿
Application.ScreenUpdate=False设置wbS=ThisWorkbook文件夹=
wbS.Path&“\”
sFile=Dir(sFolder)在sFile“”时执行
如果是sFile wbS.Name,则设置wbD=Workbooks.Open(sFolder&sFile)
"打开文件,;添加条件到
“>>>>>调整本部分wbD.Sheets(“数据”)范围(“A3:BD3”)。副本
wbS.激活工作表(“数据记分卡”).范围(“A”&
行。计数)。结束(xlUp)。偏移量(1,0)。粘贴特殊xlPasteValues
Application.CutCopyMode=False'>>>>>>wbD.Close savechanges:=True
'关闭而不保存结束,如果
sFile=Dir'下一个文件循环Application.screenUpdate=True
端接头

这看起来很合适。我使用了直接值传输,而不是复制、粘贴特殊值

Option Explicit

Sub Import_to_Master()
    Dim sFolder As String, sFile As String
    Dim wbS As Workbook

     Application.ScreenUpdating = False

     Set wbS = ThisWorkbook
     sFolder = wbS.Path & "\"
     sFile = Dir(sFolder & "*.xl*")

     Do While sFile <> ""
        If sFile <> wbS.Name Then
            'open the file; add condition to
            With Workbooks.Open(sFolder & sFile)
                ' >>>>>> Adapt this part wbD
                With .Worksheets("data").Range("A3:BD3")
                    wbS.Worksheets("data scorecards").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(.Rows.Count, .Columns.Count) = .Value
                End With
                'close without saving
                .Close savechanges:=False
             End With
        End If
        sFile = Dir 'next file
     Loop

     Application.ScreenUpdating = True

End Sub
选项显式
子导入到主控台()
Dim S文件夹作为字符串,sFile作为字符串
将wbS设置为工作簿
Application.ScreenUpdating=False
设置wbS=ThisWorkbook
sFolder=wbS.Path&“\”
sFile=Dir(sFolder&“*.xl*”)
在sFile“”时执行此操作
如果是sFile wbS.Name,则
"打开文件,;添加条件到
带工作簿。打开(文件夹和文件)
“>>>>>>>>调整此部分wbD
带有.工作表(“数据”).范围(“A3:BD3”)
wbS.工作表(“数据记分卡”).单元格(Rows.Count,“A”).结束(xlUp).偏移量(1,0).调整大小(.Rows.Count,.Columns.Count)=.Value
以
"关而不存"
.Close savechanges:=False
以
如果结束
sFile=Dir'下一个文件
环
Application.ScreenUpdating=True
端接头

只需指定图纸名称或位置,即可访问其任何值。它甚至出现在您的代码中:
Sheets(“隐藏的工作表名称”)。范围(…)
不太确定问题所在,您是否试图从隐藏的工作表进行复制并出现错误?正如@JeanRostan所指出的,您应该能够像AFAIK中的任何其他工作表一样使用隐藏工作表。