john_revelator
04-07-2009, 11:25
Salve a tutti. Sono ancora qui a rompere. :fagiano:
Tramite word dovrò importare in excel dei dati ma prima devo verificare che il file di excel sia aperto o meno.
Il codice che ho scritto finora è questo. Anche se il file è chiuso mi dice che in realtà è già aperto. Potete darmi un consiglio? Grazie ancora.
Sub cicla()
On Error GoTo apriFile:
Dim strPath As String
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
strPath = "C:\mio_path\2009-06-19.xls"
xlApp.Visible = True
If Dir(strPath) <> "" Then
'MsgBox "Il file esiste"
If Not Workbooks(strPath) Is Nothing Then
MsgBox "file aperto"
Else
MsgBox "file chiuso"
End If
Workbooks(strPath).Activate
Else
MsgBox "Il file non esiste"
Exit Sub
End If
apriFile:
If Err.Number = 9 Then
xlApp.Workbooks.Open FileName:=strPath
Resume
End If
End Sub
Tramite word dovrò importare in excel dei dati ma prima devo verificare che il file di excel sia aperto o meno.
Il codice che ho scritto finora è questo. Anche se il file è chiuso mi dice che in realtà è già aperto. Potete darmi un consiglio? Grazie ancora.
Sub cicla()
On Error GoTo apriFile:
Dim strPath As String
Dim xlApp As Excel.Application
Set xlApp = CreateObject("Excel.Application")
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
strPath = "C:\mio_path\2009-06-19.xls"
xlApp.Visible = True
If Dir(strPath) <> "" Then
'MsgBox "Il file esiste"
If Not Workbooks(strPath) Is Nothing Then
MsgBox "file aperto"
Else
MsgBox "file chiuso"
End If
Workbooks(strPath).Activate
Else
MsgBox "Il file non esiste"
Exit Sub
End If
apriFile:
If Err.Number = 9 Then
xlApp.Workbooks.Open FileName:=strPath
Resume
End If
End Sub