Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Activate Excel workbook using vbscript

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,3464
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Activate Excel workbook using vbscript
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Activate Excel workbook using vbscript - 6/21/2005 12:59:50 AM   
  BBistheKing

 

Posts: 107
Score: 0
Joined: 6/21/2005
Status: offline
I have one instance of Excel open with several workbooks open. How do I activate a specific workbook that is already open (for example a workbook called "Customer Access.xls")?

Note: These workbooks are not maximized.

_____________________________

"Live simply, that others may simply live." - Mahatma Gandhi
 
 
Post #: 1
 
 Re: Activate Excel workbook using vbscript - 6/21/2005 1:07:29 AM   
  rockocubs

 

Posts: 65
Score: 0
Joined: 4/8/2005
From:
Status: offline
This Link might help you.

http://www.microsoft.com/technet/scriptcenter/resources/officetips/mar05/tips0301.mspx

(in reply to BBistheKing)
 
 
Post #: 2
 
 Re: Activate Excel workbook using vbscript - 6/21/2005 1:15:55 PM   
  BBistheKing

 

Posts: 107
Score: 0
Joined: 6/21/2005
Status: offline
No it doesn't - it opens a new instance of Excel which is not what I want. Thanks anyway.

(in reply to BBistheKing)
 
 
Post #: 3
 
 Re: Activate Excel workbook using vbscript - 6/21/2005 11:19:32 PM   
  rockocubs

 

Posts: 65
Score: 0
Joined: 4/8/2005
From:
Status: offline
So Excel is open on your desktop but not maximized, and you want to run a script that activates a certian sheet and maximize it. Do you have any script coded yet at all?

(in reply to BBistheKing)
 
 
Post #: 4
 
 Re: Activate Excel workbook using vbscript - 6/21/2005 11:59:21 PM   
  BBistheKing

 

Posts: 107
Score: 0
Joined: 6/21/2005
Status: offline
Excel is maximized but the workBOOKS are not (for example as three windows within Excel, visible at the same time). I have lots of script written for other programs but I will only be referring to Excel for small amounts of information (either to cut and paste). I use Excel at work for recording statistics and databases I need to refer to constantly. Excel is a small part of many processes.

So what I currently do is use AppActivate ("Excel"), the script ends and I switch between workbooks manually.

All I need to be able to do is activate a particular workbook in order to use SendKeys to cut and paste. But, my limited knowledge of VBScript means I would need to resort to having an instance of Excel open for each workbook. I would prefer to have one instance of Excel open and have the workbooks open as seperate windows within Excel and activate a particular workbook.

Sorry if I was vague, I hope this makes sense.

(in reply to BBistheKing)
 
 
Post #: 5
 
 Re: Activate Excel workbook using vbscript - 6/22/2005 12:35:28 AM   
  rockocubs

 

Posts: 65
Score: 0
Joined: 4/8/2005
From:
Status: offline
So you want to be able to open Excell once and have it open a certain workbook and send information to it and then close it and then open another workbook and carry out that process.

(in reply to BBistheKing)
 
 
Post #: 6
 
 Re: Activate Excel workbook using vbscript - 6/22/2005 12:48:57 AM   
  BBistheKing

 

Posts: 107
Score: 0
Joined: 6/21/2005
Status: offline
Excel will be already open and I don't want to close any of them, because I need them open all the time. I will usually have three workbooks open called "Customer DB.xls", "Staff Stats.xls" and "Lili Stats.xls". I would like to be able to keep the files as small windows if possible.

If not, would AppActivate work if I maximize the workbooks within the one instance of Excel? For example: AppActivate ("Customer Access.xls").

(in reply to BBistheKing)
 
 
Post #: 7
 
 Re: Activate Excel workbook using vbscript - 6/22/2005 5:49:03 AM   
  Country73


Posts: 735
Score: 10
Status: offline
I think your looking for something like this: (I already have C:\Temp\Test.xls which has 3 worksheets)

strPathExcel = "c:\temp\test.xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open strPathExcel

objExcel.ActiveWorkbook.Sheets(2).Select
Set objSheet = objExcel.ActiveWorkbook.Activesheet
objSheet.Cells(1,1) = "This"
objSheet.Cells(2,1) = "is"
objSheet.Cells(3,1) = "just"
objSheet.Cells(4,1) = "a"
objSheet.Cells(5,1) = "TEST"

objExcel.ActiveWorkbook.Save
objExcel.Quit
WScript.Quit
WScript.Echo "Completed"

(in reply to BBistheKing)
 
 
Post #: 8
 
 Re: Activate Excel workbook using vbscript - 6/22/2005 11:59:44 PM   
  BBistheKing

 

Posts: 107
Score: 0
Joined: 6/21/2005
Status: offline
Nope. Thanks for your suggestions though.

(in reply to BBistheKing)
 
 
Post #: 9
 
 Re: Activate Excel workbook using vbscript - 6/23/2005 1:27:51 AM   
  BBistheKing

 

Posts: 107
Score: 0
Joined: 6/21/2005
Status: offline
Thanks for the suggestions guys, I do appreciate the effort. I got desperate and 'threw a dart in the air'...well into Google actually and you wouldn't believe it, but I found what I was after. For those who might be interested (if anybody actually is) this is the successful code to activate minimized workbooks already open in one instance of Excel:

Set objExcel = GetObject(,"Excel.Application")

With objExcel
.Visible = True
Set objWorkbook= .Workbooks("Book1")
objWorkBook.Activate
End With

I don't know why the comma before "Excel.Application" makes it work (it doesn't seem to work without it), but maybe someone with better knowledge of VBScript can explain.

(in reply to BBistheKing)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Activate Excel workbook using vbscript Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts