Solved

Modify Open Embedded Object Macro

Posted on 2014-09-18
2
402 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

685 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