•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Visual Basic 4 / 5 / 6 section within the Software Development category of DaniWeb, a massive community of 456,556 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,446 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Views: 1571 | Replies: 2
![]() |
| |
•
•
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
3d apple blue screen cocoa computer crash dell development drivers email enterprise eudora firefox framework games gnu graphics ibm intel internet java linux microsoft microsystems mozilla news next open open source open-source opengl openoffice operating os penelope programming red hat rhel server software source step sun super system ubuntu vista wesnoth windows xp
- 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


Hybrid Mode