I have a code to import data to Word from Excel. The user has an open document in Word, and wants to import data from the selected Excel workbook. This is part of the code in Word:
Dim xlApp As Excel.Application
Dim xlWbk As Excel.Workbook
Dim xlWs As Excel.Worksheet
Dim strFile As String
strFile = Excel.Application.GetOpenFilename(FileFilter:="Excel Workbooks Only (*.xlsx),*.xlsx", FilterIndex:=1, Title:="Select Excel Workbook")
Workbooks.Open (strFile)
Set xlApp = Excel.Application
xlApp.Visible = False
Set xlWbk = Excel.ActiveWorkbook
Set xlWs = xlWbk.Sheets(1)
xlWs.UsedRange.Copy
Selection.Paste
xlApp.Application.DisplayAlerts = wdAlertsNone
When the user activates the macro, the file dialog is hidden behind the Word window, and has to use Alt-tab to navigate to it. Any ways to avoid this?