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 =)

Hi,
You want to open a excel file right?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.