您好我有一个宏,我在另一个项目上使用并试图在这个上使用它。
目前我有两张Excel工作表(Excel工作表A和Excel工作表B),并且有一个宏应该在Excel工作表A的某个选项卡上取一定范围,然后将其复制到Excel工作表B中的某个选项卡上。
宏运行正常,直到某个点朝着粘贴部分进入Excel工作表B.
问题就在ThisWorkbook.Activate之后:
“表格(”GTA800-1发动机小时数“)。选择”
完整代码如下:
' open the source workbook and select the source sheet Workbooks.Open Filename:="D:My Documents\Fleet Data (Hrs, Aircraft flying, etc.)\updated_monthly_engine_hrs_97_03.xls" Sheets("PW150").Select ' copy the source range Sheets("PW150").Range("B2:G13").Select Selection.Copy ' select current workbook and paste the values ThisWorkbook.Activate Sheets("GTA800-1 Engine Hours").Select Sheets("GTA800-1 Engine Hours").Range("B2:G13").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False ' close the source workbook Windows("updated_monthly_engine_hrs_97_03.xls").Activate ActiveWorkbook.CloseHello I have a macro that I used on another project and trying to use it on this one.
Currently I have two excel sheets (Excel sheet A and Excel sheet B) and have a macro that is supposed to take a certain range on a certain tab from Excel sheet A and then copy it on a certain tab in Excel sheet B.
The macro is running fine up until a certain point towards the pasting part into Excel sheet B.
The problem is right after ThisWorkbook.Activate:
"Sheets("GTA800-1 Engine Hours").Select"
The full code is listed below:
' open the source workbook and select the source sheet Workbooks.Open Filename:="D:My Documents\Fleet Data (Hrs, Aircraft flying, etc.)\updated_monthly_engine_hrs_97_03.xls" Sheets("PW150").Select ' copy the source range Sheets("PW150").Range("B2:G13").Select Selection.Copy ' select current workbook and paste the values ThisWorkbook.Activate Sheets("GTA800-1 Engine Hours").Select Sheets("GTA800-1 Engine Hours").Range("B2:G13").Select Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False ' close the source workbook Windows("updated_monthly_engine_hrs_97_03.xls").Activate ActiveWorkbook.Close最满意答案
知道实际的错误消息会很有用,但无论如何都不需要选择:
With Workbooks.Open(Filename:="D:My Documents\Fleet Data (Hrs, Aircraft flying, etc.)\updated_monthly_engine_hrs_97_03.xls") .Sheets("PW150").Range("B2:G13").Copy ' select current workbook and paste the values ThisWorkbook.Sheets("GTA800-1 Engine Hours").Range("B2").PasteSpecial Paste:=xlValues, _ Operation:=xlNone, SkipBlanks:=False, Transpose:=False .Close End WithI'm not 100% sure what the issue was here. I just created a new tab in the worksheet and named it abc just to test it out and then the macro worked just fine. Although the naming was correct on the previous tab above ???
That previous tab was linked to access but I DID delete the link that's the only thing that I can think of that caused the error. Anyone want to follow up on this and confirm ? Otherwise this is my answer on how to solve my issue.
更多推荐
发布评论