Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Pete,
However I now get an error when the Excel macro runs Runtime error 91 Object variable or With block variable not set on the intLastRow = line of code. I have tried various ways of setting the reference to the Excel application object but to no avail. The frustrating thing is that it worked fine when it was in Personal.xls! I am sure it is a stupid error, but I just can't see it for looking! It may be, that there is no active sheet yet when your code runs. An add-in has no active sheets, so if there is no other file open yet, intLastRow = .ActiveSheet.UsedRange.Rows.Count fails. What you could do is use an OnTime event to schedule your macro to be run, containing the offending code. That way, Excel can first finish whatever it needs to load. Sub myMacro() Application.OnTime Now, "MyMacroContinued" End Sub Sub MyMacroContinued() Dim xlApp As Excel.Application Dim intLastRow As Long, strRange As String Set xlApp = GetObject(, "Excel.Application") With xlApp .ScreenUpdating = False intLastRow = .ActiveSheet.UsedRange.Rows.Count strRange = "quniAccountsExport!R1C1:R" & intLastRow & "C16" .ActiveWorkbook.PivotCaches.Add(SourceType:=xlData base, SourceData:= _ strRange).CreatePivotTable TableDestination:="", TableName:= _ "Financial Accounts", DefaultVersion:=xlPivotTableVersion10 .ActiveSheet.PivotTableWizard TableDestination:=.ActiveSheet.Cells(3, 1) .ActiveSheet.PivotTables("Financial Accounts").NullString = "0" 'etc Regards, Jan Karel Pieterse Excel MVP http://www.jkp-ads.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Using Excel with automation | Excel Discussion (Misc queries) | |||
how do i password protect an .xls file? how do i unlock it for automation. e.g. want to unlock and access a .xls from another .xls macro. | Excel Worksheet Functions | |||
Automation: Create Word file from Excel | Excel Programming | |||
Excel automation in VB.net | Excel Programming | |||
Excel Com Automation | Excel Programming |