Hello experts! I have a macro in Word that is supposed to open Excel and paste a previous selection from Word into a new spreadsheet. It all works very well, except when Excel starts up programmatically, my custom add-in does not load. It loads fine if I start Excel by itself, so it must be something with opening programmatically.
Here is the code from Word:
Can you help?
Thanks, Robert
Here is the code from Word:
Code:
Sub Exportwordtoexcel(control As IRibbonControl)
Dim wordDoc As Object
Dim oXL As Excel.Application
Dim DocTarget As Word.Document
Dim Target As Excel.Workbook
Dim tSheet As Excel.Worksheet
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 = GetObject(, "word.application")
Selection.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 = New Excel.Application
End If
oXL.Visible = True
Set Target = oXL.Workbooks.Add
Set tSheet = Target.Sheets(1)
tSheet.Paste
Else
End If
End Sub
Can you help?
Thanks, Robert