Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
![]() |
•
•
Join Date: Oct 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
Hie, i am writing my 1st programme form to automate a frequent task.
Attached is my current form.
1) open a file & sort necessary details which will be saved in a designated folder in C drive.
2) show sorted files from C drive.
3) further select & segregate files into another 2 process: Listbox2 for mount process & Listbox3 for assy process.
4) open the files from listbox2 & 3 to proceed for further sortings.
But i'm stuck at how to open the workbook(s) listed in the listboxes --> step 4.
It seems simple enough but i dunno how to ask the programme to recognize & open the files from other listboxes.
Can anyone help? Thanks =)
Attached is my current form.
1) open a file & sort necessary details which will be saved in a designated folder in C drive.
2) show sorted files from C drive.
3) further select & segregate files into another 2 process: Listbox2 for mount process & Listbox3 for assy process.
4) open the files from listbox2 & 3 to proceed for further sortings.
But i'm stuck at how to open the workbook(s) listed in the listboxes --> step 4.
It seems simple enough but i dunno how to ask the programme to recognize & open the files from other listboxes.
Can anyone help? Thanks =)
Hi,
These are the functions to open the Excel file
Private Function OpenExcelFile(strFilePath)
'***** If File is already opened
If IsFileOpen(strFilePath) Then
Set objTempXlApp = GetObject(strFilePath)
objTempXlApp.application.Visible = True
objTempXlApp.application.WindowState = vbMaximizedFocus
Set objXlWorkBook = objTempXlApp.application.Workbooks.Item(1)
Else
'***** If File is Not opened
Set objXlApp = CreateObject("Excel.Application")
Set objXlWorkBook = objXlApp.Workbooks.Open(strFilePath)
objXlApp.Visible = True
objXlApp.application.WindowState = vbMaximizedFocus
Set objXlWorkBook = objXlApp.Workbooks.Item(1)
End If
End function
Public Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long
On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0
Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select
End Function
These are the functions to open the Excel file
Private Function OpenExcelFile(strFilePath)
'***** If File is already opened
If IsFileOpen(strFilePath) Then
Set objTempXlApp = GetObject(strFilePath)
objTempXlApp.application.Visible = True
objTempXlApp.application.WindowState = vbMaximizedFocus
Set objXlWorkBook = objTempXlApp.application.Workbooks.Item(1)
Else
'***** If File is Not opened
Set objXlApp = CreateObject("Excel.Application")
Set objXlWorkBook = objXlApp.Workbooks.Open(strFilePath)
objXlApp.Visible = True
objXlApp.application.WindowState = vbMaximizedFocus
Set objXlWorkBook = objXlApp.Workbooks.Item(1)
End If
End function
Public Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long
On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error GoTo 0
Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select
End Function
![]() |
Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Doubleclick to open file. (C#)
- Can seem to open my file (C++)
- open a file and divide its data in arrays (C)
- Open any file and List. (Visual Basic 4 / 5 / 6)
- directory/file listbox (Graphics and Multimedia)
- Cannot open file : a (Windows 9x / Me)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: open commondialog code error.how do i fix this?
- Next Thread: pls give me a quiz project
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)





Linear Mode