Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default MsgBox in new instance of Excel?


Greetings all.

I have an Excel add-in that opens a template in a new instance o
Excel, distinct from the worksheet from which the add-in runs. How ca
I get a message box to appear in the new instance instead of th
original one? I'm completely stymied here.

Here is the code that launches the template:



code:
--------------------------------------------------------------------------------
Public Sub OpenExcelTemplate()

'Create Excel Objects to display reports

On Error GoTo Error_Handler

gsTemplateFile = Environ("USERPROFILE") & "\Applicatio
Data\Microsoft\Templates\" & gsTemplateFile

'Open Excel file
Set objXL = GetObject("", "Excel.Application")
Set objWorkBooks = objXL.Workbooks
Set objWorkBook = objXL.Workbooks.Open(gsTemplateFile)
Set objWorkSheets = objWorkBook.Worksheets

With objXL
.Cursor = xlWait
.StatusBar = "Generating Reports. Please be patient..."
End With

Exit Sub
Error_Handler:
LogFile.WriteLine CStr(Now()) & ": Could not open Excel Template
Error: " & Err.Number & " " & Err.Description
Err.Clear

End Sub
-------------------------------------------------------------------------------

--
JeffK62
-----------------------------------------------------------------------
JeffK627's Profile: http://www.excelforum.com/member.php...fo&userid=2692
View this thread: http://www.excelforum.com/showthread.php?threadid=40148

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default MsgBox in new instance of Excel?

You also posted this same question on the MrExcel message board. See if my
response there is a solution you can use, at:
http://www.mrexcel.com/board2/viewtopic.php?t=166529




"JeffK627" wrote in
message ...

Greetings all.

I have an Excel add-in that opens a template in a new instance of
Excel, distinct from the worksheet from which the add-in runs. How can
I get a message box to appear in the new instance instead of the
original one? I'm completely stymied here.

Here is the code that launches the template:



code:
--------------------------------------------------------------------------------
Public Sub OpenExcelTemplate()

'Create Excel Objects to display reports

On Error GoTo Error_Handler

gsTemplateFile = Environ("USERPROFILE") & "\Application
Data\Microsoft\Templates\" & gsTemplateFile

'Open Excel file
Set objXL = GetObject("", "Excel.Application")
Set objWorkBooks = objXL.Workbooks
Set objWorkBook = objXL.Workbooks.Open(gsTemplateFile)
Set objWorkSheets = objWorkBook.Worksheets

With objXL
Cursor = xlWait
StatusBar = "Generating Reports. Please be patient..."
End With

Exit Sub
Error_Handler:
LogFile.WriteLine CStr(Now()) & ": Could not open Excel Template.
Error: " & Err.Number & " " & Err.Description
Err.Clear

End Sub
--------------------------------------------------------------------------------


--
JeffK627
------------------------------------------------------------------------
JeffK627's Profile:
http://www.excelforum.com/member.php...o&userid=26928
View this thread: http://www.excelforum.com/showthread...hreadid=401484



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default MsgBox in new instance of Excel?

Tom Urtis posted a link to his interesting solution. By comparison this is a
kludge of a workaround -

Option Explicit

Public Declare Function FindWindow32 Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Public Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long

Sub testW()
Dim hw1 As Long, hw2 As Long
Dim nWinState As Long
Dim xlApp1 As Excel.Application
Dim xlApp2 As Excel.Application

Set xlApp1 = Application
Set xlApp2 = CreateObject("Excel.Application")
DoEvents ' ?
xlApp2.Visible = True

hw1 = FindWindow32(vbNullString, xlApp1.Caption)
hw2 = FindWindow32(vbNullString, xlApp2.Caption)

'minimize our Instance but make it the front window
nWinState = xlApp1.WindowState
xlApp1.WindowState = xlMinimized
SetForegroundWindow hw1

MsgBox "Hello"

' restore as was
SetForegroundWindow hw2
xlApp1.WindowState = nWinState

'do whatever with xlApp2 (the new instance)

'stop
'close the new instance & release the object var'
xlApp2.Quit
Set xlApp2 = Nothing
Set xlApp1 = Nothing

End Sub

BTW, you say your addin creates a new instance, but in your code GetObject
gets whatever running instance of Excel by chance comes to hand.

Regards,
Peter T

"JeffK627" wrote in
message ...

Greetings all.

I have an Excel add-in that opens a template in a new instance of
Excel, distinct from the worksheet from which the add-in runs. How can
I get a message box to appear in the new instance instead of the
original one? I'm completely stymied here.

Here is the code that launches the template:



code:
--------------------------------------------------------------------------

------
Public Sub OpenExcelTemplate()

'Create Excel Objects to display reports

On Error GoTo Error_Handler

gsTemplateFile = Environ("USERPROFILE") & "\Application
Data\Microsoft\Templates\" & gsTemplateFile

'Open Excel file
Set objXL = GetObject("", "Excel.Application")
Set objWorkBooks = objXL.Workbooks
Set objWorkBook = objXL.Workbooks.Open(gsTemplateFile)
Set objWorkSheets = objWorkBook.Worksheets

With objXL
Cursor = xlWait
StatusBar = "Generating Reports. Please be patient..."
End With

Exit Sub
Error_Handler:
LogFile.WriteLine CStr(Now()) & ": Could not open Excel Template.
Error: " & Err.Number & " " & Err.Description
Err.Clear

End Sub
--------------------------------------------------------------------------

------


--
JeffK627
------------------------------------------------------------------------
JeffK627's Profile:

http://www.excelforum.com/member.php...o&userid=26928
View this thread: http://www.excelforum.com/showthread...hreadid=401484



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default MsgBox in new instance of Excel?

"JeffK627"

1. Add a new Sub in a standard module in the "gsTemplateFile" workbook.
Title it "DisplayMsgBox"
2. Within this sub create your msgbox... MsgBox "Counting Sheep"
3. In your OpenExcelTemplate sub Call the new sub...
objXL Run "DisplayMsgBox"

Jim Cone
San Francisco, USA



wrote in message

Greetings all.
I have an Excel add-in that opens a template in a new instance of
Excel, distinct from the worksheet from which the add-in runs. How can
I get a message box to appear in the new instance instead of the
original one? I'm completely stymied here.

Here is the code that launches the template:
code:
--------------------------------------------------------------------------------
Public Sub OpenExcelTemplate()

'Create Excel Objects to display reports

On Error GoTo Error_Handler

gsTemplateFile = Environ("USERPROFILE") & "\Application
Data\Microsoft\Templates\" & gsTemplateFile

'Open Excel file
Set objXL = GetObject("", "Excel.Application")
Set objWorkBooks = objXL.Workbooks
Set objWorkBook = objXL.Workbooks.Open(gsTemplateFile)
Set objWorkSheets = objWorkBook.Worksheets

With objXL
Cursor = xlWait
StatusBar = "Generating Reports. Please be patient..."
End With

Exit Sub
Error_Handler:
LogFile.WriteLine CStr(Now()) & ": Could not open Excel Template.
Error: " & Err.Number & " " & Err.Description
Err.Clear

End Sub
--------------------------------------------------------------------------------


--
JeffK627
------------------------------------------------------------------------
JeffK627's Profile: http://www.excelforum.com/member.php...o&userid=26928
View this thread: http://www.excelforum.com/showthread...hreadid=401484

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default MsgBox in new instance of Excel?

Correction... omitted the dot.
should be: objXL.Run "DisplayMsgBox"
Jim Cone



"Jim Cone" wrote in message ...
"JeffK627"
1. Add a new Sub in a standard module in the "gsTemplateFile" workbook.
Title it "DisplayMsgBox"
2. Within this sub create your msgbox... MsgBox "Counting Sheep"
3. In your OpenExcelTemplate sub Call the new sub...
objXL Run "DisplayMsgBox"
Jim Cone
San Francisco, USA

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel - New Instance JMay Excel Discussion (Misc queries) 4 November 28th 09 04:55 PM
MsgBox - How to display In Other Instance of Excel Alan Excel Programming 8 August 19th 04 10:49 PM
Lock down a new instance of Excel App quartz Excel Programming 0 April 22nd 04 06:26 PM
Excel Instance FuzzyLogic Excel Programming 2 February 21st 04 03:41 PM
Second instance of Excel Dom[_2_] Excel Programming 1 August 25th 03 05:37 PM


All times are GMT +1. The time now is 02:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"