Hi all, this one is tearing my (remaining) hair out. Running the macro opens two sessions of Excel, and pastes the data into both windows. I’m guessing it has something to do with the checking to see if Excel is already open, but I’m still a novice at this. Any ideas on how to make Excel open only one time?
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 oAddIn As Excel.AddIn 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 For Each oAddIn In oXL.AddIns With oAddIn If .Installed Then .Installed = False .Installed = True End If End With Next oAddIn End If oXL.Visible = True Set Target = oXL.Workbooks.Add Set tSheet = Target.Sheets(1) tSheet.Paste Else End If End Sub