Solved

Modify Open Embedded Object Macro

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

863 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

26 Experts available now in Live!

Get 1:1 Help Now