Solved

Modify Open Embedded Object Macro

Posted on 2014-09-18
2
377 Views
Last Modified: 2014-09-18
Hi Experts,

I'm using the below code to open an embedded word document inside of a worksheet in my workbook. I would like to modify the macro so that when its run the active sheet does not change. (simply activating a defined sheet at the end of the macro doesn't work because the User Guide can be opened from multiple places/worksheets) Possible?

Sub OpenUserGuide()
 Dim oEmbFile As Object
 Application.DisplayAlerts = False
 Set oEmbFile = Sheets("UserGuide").OLEObjects("DocUserGuide")
 oEmbFile.Verb Verb:=xlPrimary
 Set oEmbFile = Nothing
 Application.DisplayAlerts = True
 End Sub

Open in new window

0
Comment
Question by:-Polak
2 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
Comment Utility
Instead of using .Activate, you could use .Select.

However, you also want to capture the name of the active sheet that the macro is run from, so I modified your code like so:
Sub OpenUserGuide()
    Dim oEmbFile As Object
    Dim strActiveSheet As String

    Application.DisplayAlerts = False
    strActiveSheet = ActiveSheet.Name
    Set oEmbFile = Sheets("UserGuide").OLEObjects("DocUserGuide")
    oEmbFile.Verb Verb:=xlPrimary
    Set oEmbFile = Nothing
    Application.DisplayAlerts = True
    Sheets(strActiveSheet).Select
End Sub

Open in new window


When I tested, it opened the Word object (created from a file), but left the sheet from which I ran the macro as the active sheet when I switched back to Excel.

Regards,
-Glenn
0
 
LVL 1

Author Closing Comment

by:-Polak
Comment Utility
Eazy-Pizy Thanks Glenn.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now