User Name Password Register
DaniWeb IT Discussion Community
All
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 361,867 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 2,414 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:
Views: 1132 | Replies: 2
Reply
Join Date: Oct 2007
Posts: 1
Reputation: huaywoon is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
huaywoon huaywoon is offline Offline
Newbie Poster

Question Open file from listbox

  #1  
Oct 24th, 2007
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 Images
File Type: bmp open problem.bmp (606.4 KB, 11 views)
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2006
Posts: 40
Reputation: maheshsayani is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
maheshsayani's Avatar
maheshsayani maheshsayani is offline Offline
Light Poster

Re: Open file from listbox

  #2  
Oct 25th, 2007
Hi,
You want to open a excel file right?
Reply With Quote  
Join Date: Jul 2006
Posts: 40
Reputation: maheshsayani is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
maheshsayani's Avatar
maheshsayani maheshsayani is offline Offline
Light Poster

Re: Open file from listbox

  #3  
Oct 25th, 2007
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Visual Basic 4 / 5 / 6 Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum

All times are GMT -4. The time now is 6:25 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC