Thread: [Solved] Opening excel from word
View Single Post
 
Old 02-25-2017, 10:32 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Try the following, however Word nd Excel formats are different from one another so I am not sure of the point of the exercise.

Code:
Sub ExportWordtoExcelNew()
Dim wordDoc As Document
Dim oXL As Object
Dim Target As Object
Dim tSheet As Object
Dim YesOrNoAnswerToMessageBox As String
Dim QuestionToMessageBox As String


    QuestionToMessageBox = "Do you want Excel to open and paste your selection?"
    YesOrNoAnswerToMessageBox = MsgBox(QuestionToMessageBox, vbYesNo, "QuikBots for Word")
    If YesOrNoAnswerToMessageBox = vbYes Then
        Set wordDoc = ActiveDocument
        wordDoc.Range.Copy

        'If Excel is running, get a handle on it; otherwise start a new instance of Excel
        On Error Resume Next
        Set oXL = GetObject(, "Excel.Application")
        If Err Then
            Set oXL = CreateObject("Excel.Application")
        End If
        On Error GoTo 0

        oXL.Visible = True
        'oXL.ActiveWindow.Close SaveChanges:=False

        Set Target = oXL.Workbooks.Add
        Set tSheet = Target.Sheets(1)
        tSheet.Paste

        'Minimize word so you can see Excel
        'wordDoc.Application.WindowState = wdWindowStateMinimize
    End If
    Set wordDoc = Nothing
    Set oXL = Nothing
    Set Target = Nothing
    Set tSheet = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote