Solved

Modify Open Embedded Object Macro

Posted on 2014-09-18
2
398 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
ID: 40330794
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
ID: 40330827
Eazy-Pizy Thanks Glenn.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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