Hello all,
I am new at VB6, but the more i learn, the more i love it! But i do have a question. I've created a form, the user has to choose an excel file from a list that they want to open, when they highlight the file name, the directory path shows up in another label box; then the user clicks the Open button to actually open the excel file for viewing. But what if the file doesn't exist yet? How do i add to my IF/Then statement a controlled message that tells the user that the file doesn't exist and to go back and select another file? Here is the code that i have so far: - Private Sub Command1_Click()
-
Dim xl
-
Dim xlsheet
-
Dim xlwbook
-
Dim MyFileName As String
-
-
Me.Label3.ShowWhatsThis
-
MyFileName = Me.Label3.Caption
-
-
If Me.Label3.Caption <> "" Or Me.Label3.Caption <> ".xls" Then
-
-
Set xl = CreateObject("Excel.Application")
-
Set xlwbook = xl.Workbooks.Open(MyFileName)
-
Set xlsheet = xlwbook.Sheets.Item(1)
-
-
xl.Visible = True
-
-
End If
-
-
End Sub
-
-
Private Sub Command2_Click()
-
Unload Form3
-
End Sub
-
-
Private Sub Form_Load()
-
List1.AddItem " BIO Only"
-
List1.AddItem " CHEM Only"
-
List1.AddItem " NUC Only"
-
List1.AddItem " ROTA Only"
-
End Sub
-
-
Private Sub List1_Click()
-
Label3.Caption = List1.Text
-
Select Case List1.ListIndex
-
Case 0
-
Label3.Caption = "C:\file1.xls"
-
Case 1
-
Label3.Caption = "C:\file2.xls"
-
Case 2
-
Label3.Caption = "C:\file3.xls"
-
Case 3
-
Label3.Caption = "C:\file4.xls"
-
End Select
-
End Sub
Thanks,
Terra
2 1409 kadghar 1,295
Recognized Expert Top Contributor
Hello all,
I am new at VB6, but the more i learn, the more i love it! But i do have a question. I've created a form, the user has to choose an excel file from a list that they want to open, when they highlight the file name, the directory path shows up in another label box; then the user clicks the Open button to actually open the excel file for viewing. But what if the file doesn't exist yet? How do i add to my IF/Then statement a controlled message that tells the user that the file doesn't exist and to go back and select another file? Here is the code that i have so far:
Thanks,
Terra
i only gave your code a fast glimpse.
Why dont you try with an error handler?
e.g. -
Sub MySub()
-
On error goto ErrHandler
-
'your code
-
exit sub
-
ErrHandler:
-
msgbox "An error ocurried"
-
end sub
You can also check the Err object as well as it properties (number, description, etc) so you can give a "profession al look" to your error handler.
Also try with another goto, or with a loop to retry loading a file if it wasnt found the first time.
HTH
Thank you so much HTH!! The error handler works great!
Terra
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: jim |
last post by:
I'm trying to stream a html page to the user as an excel
file.
I'm currently using
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "inline;
filename=download.xls "
The actual streaming and excel file are working fine but
in excel its not picking up the filename its actually
showing up as the url to the page that downloads this. I
|
by: David Krmpotic |
last post by:
hi!!
I use the following code to operate excel document:
Excel.Application excelApp = new Excel.ApplicationClass();
//excelApp.Visible = true;
string workbookPath = "c:\\eltina.xls";
Excel.Workbook excelWorkbook =
excelApp.Workbooks.Open("eltina.xls",0,false,5,"","",false,Excel.XlPlatform.
|
by: John |
last post by:
Is there a way to code the button that's available in the query
window--microsoft excel icon that exports to excel. I know
transferspreadsheet will do this---but I want the query, which is in a
pivot table view, to be exported as a pivot, not just a data list.
Does this code exist? Is it transferspreadsheet but with a twist?
|
by: Alvin Bruney |
last post by:
anybody know how to launch desktop excel from a webpage and feed it either a
dataset or a file? i've got MS sample code but it aint compiling with the
office 10 library. i wonder if they changed the libraries cuz i used object
browser and the interface they are calling doesn't exist in the class. I'm
not looking for an OWC solution either
|
by: Sam Johnson |
last post by:
HI
I tried to send the following SQL string to an open
databse, to export a table into excel format:
g.Connection = conn 'valid OleDBConnection and Command
objects
g.CommandText = "SELECT * INTO XLSTest IN 'C:\' 'Excel
8.0;' FROM Table1"
g.ExecuteNonQuery()
| |
by: Niklas |
last post by:
Hi
Before I start coding I need to be sure that nobody else has not done it yet
and that I can use it.
I need an import utility which import data from Excel to a database or some
object in .NET. The data in Excel is not in structured columns but can exist
everywhere in the workbook. For example if I am supposed to import a person
and all his/her cars which exist in a workbook I want to be able to create an
import protocol and specify...
|
by: Steve |
last post by:
I am trying to create a DLL in Visual Studio 2005-Visual Basic that contains
custom functions. I believe I need to use COM interop to allow VBA code in
Excel 2002 to access it. I've studied everything I can find on COM Interop
and .NET. I've also tried many of the 'Walkthroughs' on the MSDN site
relating to COM add-ins, .NET and Office XP but am unable to get even these
working in Excel 2002 or Word 2002.
I've installed the Office XP...
|
by: alexia.bee |
last post by:
Hi all,
In some weird reason, excel instance won;t die if i remove the comment
from 4 lines of setting values into struct.
here is a snipcode
public System.Collections.Generic.List<frmMain.sDBTest>
LoadTestSet(string TestSetFile,
System.Collections.Generic.List<frmMain.sDBTestDBviewList)
|
by: OfficeDummy |
last post by:
Hello all!
I searched the Internet and this forum for a similar problem, but I found no help... Also, I'm a complete newbie to the fascinating world of programming, VBA and Access, so my question can very well be very stupid.
The tasks are:
1)Import an Excel table into Access
2)Add a new column and fill it with variables of date/time type.
Steps 1 and 2 need to be done only once, and I've almost managed to accomplish them. Now...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |