I have a macro that takes data from an excel file and imports it into CorelDraw.
The code below is what I am using to pick which files I want the macro to use. The first time I open CorelDraw to run the macro, it works perfectly. However, if I leave the CorelDraw window open and then run the macro again, the "open file" dialog box is hidden (I have to use alt-tab to select it so I can choose the correct excel and CorelDraw files).
Any idea what is causing this problem?
Private Sub cmdSource_Click() Dim str As String Dim objFileDialog As Office.FileDialog Dim objFileDialogFilters As Office.FileDialogFilters Set objFileDialog = excelObject.Application.FileDialog(msoFileDialogType.msoFileDialogFilePicker) If CSVInitialFolder = "" Then CSVInitialFolder = "C:\Users\mypersonalcomputer\Desktop" End If With objFileDialog
'define a Filters object Set objFileDialogFilters = .Filters With objFileDialogFilters
'clear the default filters .Clear 'add a filter, all filters must start with an asterisk .Add "CSV Files", "*.csv" .Add "Excel files", "*.xls" End With .InitialFileName = CSVInitialFolder 'allow only one file to be selected .AllowMultiSelect = False Dim hxl As Long hxl = FindWindowA("XLMAIN", "Excel") If (hxl <> 0) Then res = SetForegroundWindow(hxl) End If 'show the dialog and exit if Cancel is pressed If objFileDialog.Show = 0 Then Exit Sub End If End With txtCSVFile.Text = objFileDialog.SelectedItems(1) CSVInitialFolder = Left(txtCSVFile.Text, InStrRev(txtCSVFile.Text, "\")) End Sub