VictoriaJones
Technical User
Hi,
I have written a macro (which is stored in an individual workbook) which runs correctly when using the "Tools/Macro/Macros/Run" tool-bar, however I want to assign this code to a command button.
When I do this however I get an error message: "Run Time Error 1004. Select method of Range class failed " At the:
"Rows("1:1".Select"
point in the following code:
Application.ScreenUpdating = False
Workbooks.OpenText FileName:="U:\bu-del-buyet.txt", Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True, OtherChar:="|", FieldInfo:=Array(Array(1, 1 _
), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
, 1), Array(16, 1))
Rows("1:1".Select
Selection.Insert Shift:=xlDown
Range("A1".Select
etc......
Is this because the cmd button I am using is generating and formatting another workbook? I have tried using the "Workbooks("....".Activate code before the Select Rows code (using the new workbooks temp name that excel generates when it creates it from the txt file), but this does not make any difference to the error.
If anyone can see the flaw/problem please help!!
Thanks
Victoria
I have written a macro (which is stored in an individual workbook) which runs correctly when using the "Tools/Macro/Macros/Run" tool-bar, however I want to assign this code to a command button.
When I do this however I get an error message: "Run Time Error 1004. Select method of Range class failed " At the:
"Rows("1:1".Select"
point in the following code:
Application.ScreenUpdating = False
Workbooks.OpenText FileName:="U:\bu-del-buyet.txt", Origin:=xlWindows, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=True, OtherChar:="|", FieldInfo:=Array(Array(1, 1 _
), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), _
Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15 _
, 1), Array(16, 1))
Rows("1:1".Select
Selection.Insert Shift:=xlDown
Range("A1".Select
etc......
Is this because the cmd button I am using is generating and formatting another workbook? I have tried using the "Workbooks("....".Activate code before the Select Rows code (using the new workbooks temp name that excel generates when it creates it from the txt file), but this does not make any difference to the error.
If anyone can see the flaw/problem please help!!
Thanks
Victoria