Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-01-2014, 03:37 AM
Catty Catty is offline Macro to determine if word or excel application is being used Windows 7 32bit Macro to determine if word or excel application is being used Office 2010 32bit
Advanced Beginner
Macro to determine if word or excel application is being used
 
Join Date: Nov 2013
Posts: 39
Catty is on a distinguished road
Default Macro to determine if word or excel application is being used

Hi

I have a print macro for word and one for excel. I want to combine these two. So I need my macro to:
a) Determine first which application its being called from (Word or Excel)


b) Call either the Excel or Word print macro depending on point (a)'s selection.

Thanks in advance.
Reply With Quote
  #2  
Old 04-01-2014, 05:31 AM
Charles Kenyon Charles Kenyon is offline Macro to determine if word or excel application is being used Windows 7 64bit Macro to determine if word or excel application is being used Office 2010 32bit
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,165
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Code:
Sub whichApp()
  dim sApp as String
  sApp = Application.Name
  msgBox "Application is " & sApp
End Sub
Have a test for the value of sApp. It will be either "Microsoft Word" or "Microsoft Excel." Or, you could pass sApp as a parameter to your called procedure.
Reply With Quote
  #3  
Old 04-01-2014, 08:13 PM
macropod's Avatar
macropod macropod is offline Macro to determine if word or excel application is being used Windows 7 32bit Macro to determine if word or excel application is being used Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by Catty View Post
I have a print macro for word and one for excel. I want to combine these two.
Since the Word and Excel object models are quite different and the files they work with are entirely different, I doubt you'll be able to do this in a straightforward way.

In any event, unless your print macro is re-written as a vbscript (which is stored in a file on its own and requires it own automation by each calling application), you can't have the two applications call the shared macro without each application having a macro of its own to call the shared one, which kind of defeats the purpose.

If the code isn't re-written as a vbscript and one application hosts the macro, whichever application doesn't host it will have to automate the other one to do the printing on it's behalf, thus requiring far more code than you'll ever be likely to save.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to determine if word or excel application is being used application wide macro ronaldo.k PowerPoint 1 11-21-2013 11:31 AM
Macro to determine if word or excel application is being used cannot start the source application for this object - Excel charlesmac Excel 3 08-15-2012 05:22 AM
Macro to determine if word or excel application is being used A word macro application Hikmetotheron Word 3 04-26-2011 02:01 PM
Macro to determine attached template zippyaus Word VBA 0 03-02-2010 02:05 AM
Macro to determine if word or excel application is being used Excel 2003 will not terminate with application.quit Peter Schellenbach Excel 12 03-14-2006 05:28 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft