我已根据以下代码合并了工作簿数据:
Restangular.setRequestInterceptor(function (element, operation, what, url) {
$rootScope.validationErrors = [];
activeRequests++;
$rootScope.loading = true;
return element;
})
现在的问题是,每个单独的工作簿都有一个带宏的按钮和按钮单击时的一些代码,它在单个文件中正常工作但在合并文件中单击按钮然后它打开原始文件以运行代码按钮单击,它不使用在合并文件中复制的代码。
让我知道如何确保合并文件不依赖于原始文件来运行按钮点击代码,并且应该是独立的。
评论中提到的单个按钮点击代码:
Sub Merge2MultiSheets()
Dim wbDst As Workbook
Dim wbSrc As Workbook
Dim wsSrc As Worksheet
Dim MyPath As String
Dim strFilename As String
Dim CurrentRow As Integer
Dim CurrentColumn As Integer
Dim Index As Integer
Application.DisplayAlerts = False
Application.EnableEvents = False
Application.ScreenUpdating = False
MyPath = "D:\Excels" ' change to suit
CurrentRow = 1
CurrentColumn = 1
Index = 0
Set wbSource = ActiveWorkbook
strFilename = wbSource.Worksheets("Test").Cells(CurrentRow, Index + 1)
Set wbDst = Workbooks.Add(xlWBATWorksheet)
'strFilename = Dir(MyPath & "\*.xlsx", vbNormal)
If Len(strFilename) = 0 Then Exit Sub
Do Until strFilename = ""
Set wbSrc = Workbooks.Open(fileName:=MyPath & "\" & strFilename)
Set wsSrc = wbSrc.Worksheets(1)
wsSrc.Copy after:=wbDst.Worksheets(wbDst.Worksheets.Count)
Set wsSrc = wbSrc.Worksheets(2)
wsSrc.Copy after:=wbDst.Worksheets(wbDst.Worksheets.Count)
wbSrc.Close False
Index = Index + 1
strFilename = wbSource.Worksheets("Test").Cells(CurrentRow, Index + 1)
Loop
wbDst.Worksheets(1).Delete
Application.DisplayAlerts = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:1)
我测试了代码,问题似乎仅限于表单按钮。尝试使用ActiveX按钮
在开发者标签中,在控件组中,单击“插入”下拉按钮,您会注意到有2个分组,上部分组带有标题表单控制并降低标题为 ActiveX控件的标题。从ActiveX控件插入按钮。
答案 1 :(得分:0)
如果要运行特定于正在执行的合并文件的宏,请前言:
Call Thisworkbook.MacroName
确保在执行之前初始化到工作簿中的正确页面。您也可以使用Thisworkbook控制它。
Thisworkbook.Sheetname
这将使您的执行不会在原始图书中运行。