+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    10-29-2009
    Location
    TOKIO
    MS-Off Ver
    Excel 2003
    Posts
    1

    Msg Box in Excel From Word

    Hello. I hope this is the right place for this question.

    I have a Word macro that copies a table to a new Excel document.
    That part is working fine. But once the item has been pasted, I want a message box to open IN EXCEL to tell the user what to do next.

    So far, no matter what I do, the MsgBox only displays in Word, which is useless to me.

    How can I specify that the MsgBox should be in EXCEL?

    Code is below.

    Code:
    Sub BackupTable()
    Selection.WholeStory
    Selection.Copy
    Dim Excel
    Set Excel = CreateObject("excel.application")
    Excel.Visible = True
    Set oWB = Excel.Workbooks.Add
    Set oWS = oWB.Worksheets(1)
    With oWS
    .Range("A1").Select
    oWS.Paste
    End With
    With oWS
    If .Range("A1") > 0 Then
                   MsgBox "Please double-check that no images have been copied, and move on to the next step."
               End If
    End With
    End Sub
    Last edited by yukimatsu; 10-29-2009 at 06:13 AM. Reason: code tags were missing

  2. #2
    Forum Moderator pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,141

    Re: Msg Box in Excel From Word

    Hi yukimatsu
    If you have a module in the word Document with the messagebox sub
    export and import the module to the excel workbook then run the sub
    Code:
    Option Explicit
    
    Sub CopyAModule(wkbFrom As String, _
                                wkbTo As String, _
                                strFromMod As String)
        Dim wkb As Workbook
        Dim strFile As String
        
        Set wkb = Workbooks(wkbFrom)
        
        strFile = wkb.Path & "\vbCode.bas"
        wkb.VBProject.VBComponents(strFromMod).Export strFile
        
        On Error Resume Next
        Set wkb = Workbooks(wkbTo)
        If Err.Number <> 0 Then
            Workbooks.Open wkbTo
            Set wkb = Workbooks(wkbTo)
        End If
        
        wkb.VBProject.VBComponents.Import strFile
        wkb.Save
        
        Set wkb = Nothing
    End Sub
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    JBeaucaires Excel Files

    VBA for smarties - snb

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0