FredrikNilsen
New Member
- Joined
- Jan 25, 2021
- Messages
- 26
- Office Version
- 365
- 2019
- 2016
- 2013
- Platform
- Windows
Hello,
I have a code to import data to Word from Excel. This is part of the code:
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?
I have a code to import data to Word from Excel. This is part of the code:
VBA Code:
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?