B
BW
I'm a novice at the vba side of things and need a "cleaner" excel output
than just transfereing a table to spreadsheet or outputing a report to
excel.
I have created the following function to create an excel sheet and populat
the following information. (I will be adding rows of data after I get this
fixed but needed a starting point).
The function runs and creates the excel sheet and puts all of the
informaiton into it. But if I try and run the code again to create a
second sheet it gives me the following error
Run-time error '1004'
Method 'Range' of object'_Global' failed
It starts the next instance of excel before it errors out.
I also have to admit that the code that puts the informaiton in the cells
was copied from a Macro I recorded in excel to see what syntax needed to be
used.
What am I doing wrong with this?
Thanks in advance...
BW
Function FreddieMacBilling()
Dim xlapplication As Excel.Application
Dim xlworkbook As Excel.Workbook
Set xlapplication = CreateObject("excel.application")
xlapplication.Visible = True
Set xlworkbook = xlapplication.Workbooks.Add
Range("A1").Select
ActiveCell.FormulaR1C1 = "Company Name"
Range("B1").Select
ActiveCell.FormulaR1C1 = "ABC CORP"
Range("C1").Select
ActiveCell.FormulaR1C1 = "5555555-555"
Range("D1").Select
ActiveCell.FormulaR1C1 = "bla bla bla Anytown , IN 55555"
Range("E1").Select
ActiveCell.FormulaR1C1 = "555-555-5555"
Range("B3").Select
ActiveCell.FormulaR1C1 = "Billing"
Range("C3").Select
ActiveCell.FormulaR1C1 = "12/1/2006"
Range("F3").Select
ActiveCell.FormulaR1C1 = "Spreedsheet 12012006"
Range("A5").Select
End Function
than just transfereing a table to spreadsheet or outputing a report to
excel.
I have created the following function to create an excel sheet and populat
the following information. (I will be adding rows of data after I get this
fixed but needed a starting point).
The function runs and creates the excel sheet and puts all of the
informaiton into it. But if I try and run the code again to create a
second sheet it gives me the following error
Run-time error '1004'
Method 'Range' of object'_Global' failed
It starts the next instance of excel before it errors out.
I also have to admit that the code that puts the informaiton in the cells
was copied from a Macro I recorded in excel to see what syntax needed to be
used.
What am I doing wrong with this?
Thanks in advance...
BW
Function FreddieMacBilling()
Dim xlapplication As Excel.Application
Dim xlworkbook As Excel.Workbook
Set xlapplication = CreateObject("excel.application")
xlapplication.Visible = True
Set xlworkbook = xlapplication.Workbooks.Add
Range("A1").Select
ActiveCell.FormulaR1C1 = "Company Name"
Range("B1").Select
ActiveCell.FormulaR1C1 = "ABC CORP"
Range("C1").Select
ActiveCell.FormulaR1C1 = "5555555-555"
Range("D1").Select
ActiveCell.FormulaR1C1 = "bla bla bla Anytown , IN 55555"
Range("E1").Select
ActiveCell.FormulaR1C1 = "555-555-5555"
Range("B3").Select
ActiveCell.FormulaR1C1 = "Billing"
Range("C3").Select
ActiveCell.FormulaR1C1 = "12/1/2006"
Range("F3").Select
ActiveCell.FormulaR1C1 = "Spreedsheet 12012006"
Range("A5").Select
End Function