Excel Find Cell/GetObject

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Excel Find Cell/GetObject

Post by Dominic_Fichera » Wed Oct 14, 2015 2:58 am

Hey all,

I'm working on a script which essentially opens an excel document in the background, searches for a cell and returns the co-ords. I've based my script off the one Marcus posted here https://www.mjtnet.com/blog/2010/12/15/ ... -vbscript/, but with one key change. I noticed that Marcus posted a small disclaimer that said the code would not work if multiple instances of Excel were open... Well, that's the case, so I went exploring to https://support.microsoft.com/en-us/kb/288902 and found that instead of using

Code: Select all

Set xlApp = GetObject(,"Excel.Application")
, I should be able to use

Code: Select all

Set xlApp = GetObject("Book2").Application
where "Book2" is the name of the spreadsheet.

when I put this into Macro Scheduler and run it, I receive the following error:

Code: Select all

Macro Scheduler

:-2147221020

Line 11334, Column 4
The location mentioned in the error is the start of the Set xlApp line of code.

I've played around with different Excel filetyped (.xlsx, .xlsb, .csv), changed the name to something less complex (no spaces, hyphons, numbers etc) and all the same.

Any ideas?

Thanks in advance, as always,

Dominic Fichera

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Re: Excel Find Cell/GetObject

Post by armsys » Wed Oct 14, 2015 7:46 am

May we see a major/relevant portion of your code so that we can learn about Excel scripting?
Thanks.

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Excel Find Cell/GetObject

Post by hagchr » Wed Oct 14, 2015 7:50 am

Hi, It seems to work if you use the full path.

Code: Select all

xlApp = GetObject("C:\Users\...\Book1.xlsx").Application

Dominic_Fichera
Pro Scripter
Posts: 82
Joined: Mon Mar 24, 2014 12:15 pm

Re: Excel Find Cell/GetObject

Post by Dominic_Fichera » Thu Oct 15, 2015 12:24 am

hagchr wrote:Hi, It seems to work if you use the full path.

Code: Select all

xlApp = GetObject("C:\Users\...\Book1.xlsx").Application

That works perfectly, hagchr! Thanks! :)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts