Hi everybody,
I want to say that my experience with VBA is average. I cannot build full codes by myself, but I can modify most of the available temaplates
for my own purposes. But lets jump straight to my (weird) question:
I have developed a macro code which works absolutely fine from the workbook itself, but when I try to make it global (save it as an "add-in") I receive all sorts of errors. I believe that new "add-in" file has already a default "Sheet1" which perhaps messes up with my formulas. Besides that I have absolutely no clue why it works one way and not the other.
For Example:
The above macro (part of the full vba code) simply copy pastes a header from one document to another, which again works fine alone. When I try to make it global it simply doesn't.
Any input is much appreciated.
Regards,
M.
I want to say that my experience with VBA is average. I cannot build full codes by myself, but I can modify most of the available temaplates
for my own purposes. But lets jump straight to my (weird) question:
I have developed a macro code which works absolutely fine from the workbook itself, but when I try to make it global (save it as an "add-in") I receive all sorts of errors. I believe that new "add-in" file has already a default "Sheet1" which perhaps messes up with my formulas. Besides that I have absolutely no clue why it works one way and not the other.
For Example:
Code:
Sub Copy_Header()
ActiveSheet.Name = "Sheet1"
Range("A1").EntireRow.Insert
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Dim wbCopy As Workbook
Dim wsCopy As Worksheet
Dim rngCopy As Range
Dim wbPaste As Workbook
Dim wsPaste As Worksheet
Dim rngPaste As Range
Set wbCopy = Workbooks.Open("Y:\Carriers\UPS\Header.xls") 'change path
Set wsCopy = wbCopy.Worksheets("Header")
Set rngCopy = wsCopy.Range("a1:ip1")
Set wbPaste = ThisWorkbook
Set wsPaste = wbPaste.Worksheets("Sheet1") 'paste to different sheet?
Set rngPaste = wsPaste.Range("a1") 'change this if needed
rngCopy.Copy
rngPaste.PasteSpecial
Application.DisplayAlerts = False
Workbooks("Header.xls").Close
End Sub
The above macro (part of the full vba code) simply copy pastes a header from one document to another, which again works fine alone. When I try to make it global it simply doesn't.
Any input is much appreciated.
Regards,
M.
Last edited by a moderator: