Hello,
I am using VBA from MS Access to create an instance of Excel and of Word, and then to copy and paste from Excel into Word. When I execute, the first time it runs properly, the second time I get this error message:
Run Time Error #91
Object Variable or With Block Variable not Set.
here is the code where it hangs:
appExcel.ActiveWorkbook.Worksheets.Add
appExcel.ActiveSheet.Name = "Ticket_format1"
appExcel.Worksheets("Receipt_Ticket").Activate
appExcel.Range("a1").Select
rowcnt_excel_1 = appExcel.ActiveCell.CurrentRegion.Rows.Count - 1
colcnt_excel_1 = appExcel.ActiveCell.CurrentRegion.Columns.Count - 1
'trouble area below
'name321 = appExcel.ActiveSheet.Name
appExcel.CutCopyMode = False
appExcel.Workbooks(bookname_excel_1).Sheets("Receipt_Ticket").Range(ActiveCell.Address, ActiveCell.Offset(rowcnt_excel_1, colcnt_excel_1).Address).Select
here is the line that it hangs up on:
'appExcel.ActiveSheet.Range(ActiveCell.Address, ActiveCell.Offset(rowcnt_excel_1, colcnt_excel_1).Address).Select
appExcel.Selection.Copy
I have looked at all of the resources, and I don't understand what is going on. I have made sure that there are no other instances of excel or word open (just manually, not programatically). Any help is greatly appreciated!!
Thank you to all. This forum has been very helpful to me in the past when I hit a wall. Thank you!!!!
PS... I would like to understand why it runs once, but will not run again without error.
Pat
I am using VBA from MS Access to create an instance of Excel and of Word, and then to copy and paste from Excel into Word. When I execute, the first time it runs properly, the second time I get this error message:
Run Time Error #91
Object Variable or With Block Variable not Set.
here is the code where it hangs:
appExcel.ActiveWorkbook.Worksheets.Add
appExcel.ActiveSheet.Name = "Ticket_format1"
appExcel.Worksheets("Receipt_Ticket").Activate
appExcel.Range("a1").Select
rowcnt_excel_1 = appExcel.ActiveCell.CurrentRegion.Rows.Count - 1
colcnt_excel_1 = appExcel.ActiveCell.CurrentRegion.Columns.Count - 1
'trouble area below
'name321 = appExcel.ActiveSheet.Name
appExcel.CutCopyMode = False
appExcel.Workbooks(bookname_excel_1).Sheets("Receipt_Ticket").Range(ActiveCell.Address, ActiveCell.Offset(rowcnt_excel_1, colcnt_excel_1).Address).Select
here is the line that it hangs up on:
'appExcel.ActiveSheet.Range(ActiveCell.Address, ActiveCell.Offset(rowcnt_excel_1, colcnt_excel_1).Address).Select
appExcel.Selection.Copy
I have looked at all of the resources, and I don't understand what is going on. I have made sure that there are no other instances of excel or word open (just manually, not programatically). Any help is greatly appreciated!!
Thank you to all. This forum has been very helpful to me in the past when I hit a wall. Thank you!!!!
PS... I would like to understand why it runs once, but will not run again without error.
Pat