Solved

Modify Open Embedded Object Macro

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

776 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