473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Excel VBA set active document

142 100+
help please,
I use excel VBA to open a MS application and set that application's document as activedocument. After the first MS application opened the excel VBA open another MS application and set that application's document as activedocument. After the second application quit, I need the excel automative detect the first opened MS application back as active application. How can it possible?
thanks
Apr 24 '07 #1
6 28787
joemo2003
142 100+
help please,
I use excel VBA to open a MS application and set that application's document as activedocument. After the first MS application opened the excel VBA open another MS application and set that application's document as activedocument. After the second application quit, I need the excel automative detect the first opened MS application back as active application. How can it possible?
thanks
never mind
Apr 24 '07 #2
Killer42
8,435 Expert 8TB
never mind
I'll notify the team to stop work on this immediately. ;)
Apr 25 '07 #3
joemo2003
142 100+
I'll notify the team to stop work on this immediately. ;)
Actually, i still need help on that. There is a little bit change on the description above. Instead open two MS application but only one MS application with two workbooks. And the second workbooks should not be quit but just finish runing.
So the full description should be:
I use excel VBA to open a MS application and set document(A) as activedocument. After the document(A) opened, the excel VBA open document(B) in the same MS application and set that document(B) as activedocument. After VBA finish using document(B), with leaving document(B) open, I need the excel automative detect the document(A) back as active document. How can it possible?
Thanks
Apr 25 '07 #4
SammyB
807 Expert 512MB
>open a MS application
What application?

>set document(A) as activedocument
How? Be sure to save a reference to this doc.

>detect the document(A) back as active document.
Use the code above (the "How?") with the saved reference.

If this is all Excel, then after activating A:
Set wbA = ActiveWorkbook

Then when you want to switch back to A
wbA.Activate

In fact Activate should do the trick for most MS apps. Works for Word. but not for Access (but, nothing works the same for Access).
Apr 30 '07 #5
joemo2003
142 100+
>open a MS application
What application?

>set document(A) as activedocument
How? Be sure to save a reference to this doc.

>detect the document(A) back as active document.
Use the code above (the "How?") with the saved reference.

If this is all Excel, then after activating A:
Set wbA = ActiveWorkbook

Then when you want to switch back to A
wbA.Activate

In fact Activate should do the trick for most MS apps. Works for Word. but not for Access (but, nothing works the same for Access).
what I do just set up two functions in module, they are the same except one function declare another application at begining and Set app=nothing at the end, and then use the Call function to call those two function. I was thinking it may open a new application window, but it won't, so it work.
thanks anywhere
Apr 30 '07 #6
To the poster above, if you're having trouble with the macro reference (if you are only doing one file) in Excel (I don't know about other products - didn't try) but you can just add this line after your initial open:

ActiveWindow.ActivateNext

because excel opens new windows to open files in macros, its still looking at the window with your initial file. This will force it to open the next window.

Now, I'm having a similar problem to him, but somewhat more complicated. Mine is running a loop to open all files in a particular folder, print them and close them. I have the macro working - to some degree. here is my code (this is excel):
Expand|Select|Wrap|Line Numbers
  1. Sub RMPProducer()
  2.  
  3.   OldPath = "S:\RMBS_Performance_Analytics\Analysis\1 Staging Folder For Monthly Model Templates\2007\200704\VV\Deals"
  4.   Dim t As Workbook
  5.   Dim s As String
  6.   Dim a As Window
  7.  
  8.   With Application.FileSearch
  9.     .NewSearch
  10.     .LookIn = OldPath
  11.     .SearchSubFolders = False
  12.     .Filename = "*.xls"
  13.     .MatchTextExactly = True
  14.     If .Execute() > 0 Then
  15.       For i = 1 To .FoundFiles.Count
  16.         s = .FoundFiles(i)
  17.         Workbooks.Open (s)
  18.         Set t = Workbooks(i)
  19.         t.Activate
  20.         ActiveWindow.ActivateNext
  21.         ActiveWorkbook.Sheets("Summary").Select
  22.         ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
  23.         ActiveWorkbook.Sheets("Collateral Graphs").Select
  24.         ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
  25.         ActiveWorkbook.Sheets("CLASS CE GRAPH").Select
  26.         ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
  27.         ActiveWorkbook.Sheets("XS AND OC TABLE").Select
  28.         ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
  29.       Next i
  30.     Else
  31.       MsgBox "There were no files found."
  32.     End If
  33.   End With
  34. End Sub
I have 2 problems. First problem is that I am trying to add a function to make the window close once its finished printing. This actually works - but it limits my loop iterations from i = 1 to 2 (so it only runs 2 times and I'm not exactly sure why). If I don't include the statement - this can run for up to 7 - 8 times (these are very large files) then excel runs out of memory. Unfortunately, i can't set the loop to run from i = anything other than one.

So What I would prefer is to be able to actually activate the ActiveWindow.close command - because this way I can run the entire loop. But I'm not sure how to. I tried window referencing, I tried adding a new active Window so when the file opens, its opening in the active window already, but nothing works.

Preferably, I need to be able to reference both windows, as my next macro will involve referencing 2 windows (one static - always open) and the other the loop above.

Anyone have any ideas/ All help is appreciated.
May 7 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Pawel | last post by:
Hello All I tried to embed Excel sheet into HTML page by following command: <iframe src="Tmp.XLS" width="100%" height="500"></iframe> and it works, showing Excel sheet inside the page, but...
1
by: c duden | last post by:
Excel won't allow documents to be linked to a worksheet in office 2000 when using C# to create an add-in. The following code snippets are what was used in the attempts (there are more...
1
by: Josh Schmidt | last post by:
I'm using the Excel application object to create a spreadsheet from a recordset. Everything seems to work fine except any date fields are not displaying properly. For example 4/18/2004 is...
0
by: ImraneA | last post by:
Hi there Many thanks to those people who contributed to this group, helped me greatly. Enclose, my code, hope it helps others :- Public Function Export_Excel_9(tbx1 As Variant, tbx2 As...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
8
by: Brian Keating | last post by:
hello, i've got a very simple requirment, i want to load excel into a WindowsForm (just like Iexplore.exe can load excel) I'm guessing that this is gonna be done with Ole automation somehow?...
3
by: hkappleorange | last post by:
I connect to mdb file using the following codes. How should I modify it if I want to connect to Excel instead ? <%@ Import Namespace="System.Data.OleDb" %> <% Dim conAuthors As...
18
by: Frank M. Walter | last post by:
Hello, I have made an small AddIn with udf for excel 2003. I use vs2003. The point of view is the function __T() I call it in excel sheet writing =__T() I am not able to set a value to a...
24
rauty
by: rauty | last post by:
Hi all, I'm trying to access the most recent instance of Excel so I can paste data. What works for me is if Excel isn't already opened, I open it and can paste the data where I want to. What...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.