我是Excel VBA的新手,我没有编程背景。
我正在尝试对打开的工作簿进行格式更改,然后将存储在同一目录中的公共单独工作簿文件中的数据复制并粘贴到打开的工作簿中,可能没有"激活"公共/参考工作手册。
我要复制公共数据的文件是CUSTOMER FINAL FOR INSPECTION REPORTS DW.xlsx。另一个文件VIBRA PARKING LOT是我想要运行宏的那个文件,除了这会随着我打开我要应用相同宏的后续工作簿而改变。所以VIBRA PARKING LOT不是静态参考。 (我想我希望引用是开放的,活动的工作簿。)
我很想说答案涉及从参考电子表格调用数据而不激活它,这样宏就不必来回切换激活,这样它就不会调用特定的电子表格了。我最初编程宏。或者答案涉及定义变量电子表格,我正在应用宏,因为当时打开的是什么,同时保持我正在复制数据的参考电子表格不变。
我尝试研究这个并对代码应用更改,但我无法正常工作。
这是我的代码:
With ActiveWindow
.Top = 255.25
.Left = 19.75
End With
With ActiveWindow
.Width = 1351.5
.Height = 348
End With
Range("A1:L142").Select
Range("G44").Activate
With Selection.Font
.Name = "Calibri"
.Size = 8
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor
End With
Selection.EntireColumn.Hidden = False
ActiveWindow.FreezePanes = False
Range("E6").Select
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Sheets("General Requirements").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Light & Ventillation").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Plumbing Facilities").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Mechanical and Electrical").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Fire Safety").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Sheet1").Select
ActiveWindow.SelectedSheets.Delete
Columns("B:B").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Windows("1 CUSTOMER FINAL FOR INSPECTION REPORTS DW.xlsx").Activate
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
Columns("A:G").Select
Selection.Copy
Windows("0171927117002 Vibra Parking Lot 020217.xlsx").Activate
Columns("A:G").Select
ActiveSheet.Paste
Windows("1 CUSTOMER FINAL FOR INSPECTION REPORTS DW.xlsx").Activate
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
Columns("N:N").Select
Application.CutCopyMode = False
Selection.Copy
Windows("0171927117002 Vibra Parking Lot 020217.xlsx").Activate
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 7
Columns("N:N").Select
ActiveSheet.Paste
Range("P5").Select
ActiveWindow.ScrollColumn = 6
ActiveWindow.ScrollColumn = 5
ActiveWindow.ScrollColumn = 4
ActiveWindow.ScrollColumn = 3
ActiveWindow.ScrollColumn = 2
ActiveWindow.ScrollColumn = 1
End Sub