•
•
•
•
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,560 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,470 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: 1554 | Replies: 7
![]() |
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
i have a problem with my code... i use this code to open an excel and manipulate the data
it works well accept a few things
when the browse menu opened so i can choose which file to manipulate
if i double click the file i want to open = its open and good
if i click a file once and click button open = its open and good
if i didnt click anything and close the open window = its error to my application
if i click a file and click cancel = its error to my application
how do i fix this?
another question is when the commondialog opened. how can i set it so user can only choose excel file only.this is to reduce human error.
thanks
Dim xl3 As Excel.Application
Dim xl3sheet As Excel.Worksheet
Dim xl3wbook As Excel.Workbook
Dim FilNam As String
Me.CommonDialog1.ShowOpen
FilNam = Me.CommonDialog1.Filename
If Me.CommonDialog1.Filename <> "" Or Me.CommonDialog1.Filename <> ".xls" Then
Set xl3 = CreateObject("Excel.Application")
Set xl3wbook = xl3.Workbooks.Open(FilNam)
Set xl3sheet = xl3wbook.Sheets.Item(1)
xl3.Worksheets("SYS_SUMM").Activate
xl3.Range("G25:L27").Copy
....... 'manipulating data
Application.CutCopyMode = False
xl15.DisplayAlerts = False
xl15.Workbooks.Close
xl15.Quit
Set xl15 = Nothing
Set xl15wbook = Nothing
Set xl15sheet = Nothing
End If
End Sub
when the browse menu opened so i can choose which file to manipulate
if i double click the file i want to open = its open and good
if i click a file once and click button open = its open and good
if i didnt click anything and close the open window = its error to my application
if i click a file and click cancel = its error to my application
how do i fix this?
another question is when the commondialog opened. how can i set it so user can only choose excel file only.this is to reduce human error.
thanks
Last edited by six888 : Oct 23rd, 2007 at 11:13 pm.
•
•
Join Date: Nov 2006
Posts: 30
Reputation:
Rep Power: 2
Solved Threads: 4
•
•
•
•
if i didnt click anything and close the open window = its error to my application
if i click a file and click cancel = its error to my application
These two errors can be fixed by the following condition
FilNam = Me.CommonDialog1.Filename
If FilNam =False Then
Exit Sub
End If
•
•
•
•
another question is when the commondialog opened. how can i set it so
user can only choose excel file only.this is to reduce human error.
Use the Filter Property to ".xls"
www.easyprograming.com
Make Your Programing Easy
Make Your Programing Easy
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
hey yello thanks for your help in the commondialog open
my project is now 98% complete thanks to you. however i have 2 concern.
i hope you can help me on this.
1) i cant find a way to make commondialog for save as. i know it should be quite similar to the commondialog open that but i cant make it out. i find a few code on the net but cant be used because most of them use
ActiveWorkbook.SaveAs
while my program is closing another workbook that is not active. it should start with something like this i guess
excel2.????.????
2) my program take too long to execute. and sometimes its shows "waiting another ole to execute" msgbox. i dont know why. at 1st i thought it was because of insufficient RAM. but maybe something wrong with my code
my project is now 98% complete thanks to you. however i have 2 concern.
i hope you can help me on this.
1) i cant find a way to make commondialog for save as. i know it should be quite similar to the commondialog open that but i cant make it out. i find a few code on the net but cant be used because most of them use
ActiveWorkbook.SaveAs
while my program is closing another workbook that is not active. it should start with something like this i guess
excel2.????.????
2) my program take too long to execute. and sometimes its shows "waiting another ole to execute" msgbox. i dont know why. at 1st i thought it was because of insufficient RAM. but maybe something wrong with my code
•
•
Join Date: Nov 2006
Posts: 30
Reputation:
Rep Power: 2
Solved Threads: 4
Instead of
Me.CommonDialog1.ShowOpen
you can use
Me.CommonDialog1.ShowSave
This will open the save dialog box.
If you post the complete code then I can check why it is taking long time
Me.CommonDialog1.ShowOpen
you can use
Me.CommonDialog1.ShowSave
This will open the save dialog box.
If you post the complete code then I can check why it is taking long time
www.easyprograming.com
Make Your Programing Easy
Make Your Programing Easy
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
im actually building a reporting automation
this is my code for open new excel.it works well
Dim xln As Excel.Application
Dim xlnwbook As Excel.Workbook
Dim xlnwSheet As Excel.Worksheet
Set xln = CreateObject("Excel.Application")
Set xlnwbook = xln.Workbooks.Add
then i open other excel file and copy some data to the new excel file i just opened.
then i want to save the new excel file
here is the code
Set xln = CreateObject("Excel.Application")
CommonDialog1.Filter = "Microsoft Office Excel (*.xls)|*.xls"
Me.CommonDialog1.ShowSave
FilNam = Me.CommonDialog1.Filename
xln.Application.ActiveWorkbook.SaveAs (FilNam)
xln.Application.ActiveWorkbook.Save
Me.CommonDialog1.Filename = ""
If CloseMode <> 1 Then Cancel = 1
End Sub
but i wont work.please help
this is my code for open new excel.it works well
Dim xln As Excel.Application
Dim xlnwbook As Excel.Workbook
Dim xlnwSheet As Excel.Worksheet
Set xln = CreateObject("Excel.Application")
Set xlnwbook = xln.Workbooks.Add
then i open other excel file and copy some data to the new excel file i just opened.
then i want to save the new excel file
here is the code
Set xln = CreateObject("Excel.Application")
CommonDialog1.Filter = "Microsoft Office Excel (*.xls)|*.xls"
Me.CommonDialog1.ShowSave
FilNam = Me.CommonDialog1.Filename
xln.Application.ActiveWorkbook.SaveAs (FilNam)
xln.Application.ActiveWorkbook.Save
Me.CommonDialog1.Filename = ""
If CloseMode <> 1 Then Cancel = 1
End Sub
but i wont work.please help
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
hey... now i can save with this code
Set xln = CreateObject("Excel.Application")
CommonDialog1.Filter = "Microsoft Office Excel (*.xls)|*.xls"
Me.CommonDialog1.Filename = "report"
Me.CommonDialog1.ShowSave
FilNam = Me.CommonDialog1.Filename
xlnwbook.SaveAs (FilNam)
Set xln = Nothing
Set xlnwbook = Nothing
Set xlnsheet = Nothing
but there is still some problem
because i set filename default to report.xls.
whenever i just click ok when there is already a file name report.xls
it will be error
however...
the other way... i put filename default to "" and i type report.xls myself
it will produce a msgbox of asking if its ok to replace existing the file
if i click ok.. then it save.. if i click no.. then it error
what i suppose to do to not produce error in this two occasion?
Set xln = CreateObject("Excel.Application")
CommonDialog1.Filter = "Microsoft Office Excel (*.xls)|*.xls"
Me.CommonDialog1.Filename = "report"
Me.CommonDialog1.ShowSave
FilNam = Me.CommonDialog1.Filename
xlnwbook.SaveAs (FilNam)
Set xln = Nothing
Set xlnwbook = Nothing
Set xlnsheet = Nothing
but there is still some problem
because i set filename default to report.xls.
whenever i just click ok when there is already a file name report.xls
it will be error
however...
the other way... i put filename default to "" and i type report.xls myself
it will produce a msgbox of asking if its ok to replace existing the file
if i click ok.. then it save.. if i click no.. then it error
what i suppose to do to not produce error in this two occasion?
•
•
Join Date: Nov 2006
Posts: 30
Reputation:
Rep Power: 2
Solved Threads: 4
Its all your selection to replace the file or not.
But you avoid this message box from excel.
After you create an instance of excel ie,
Set xln = CreateObject("Excel.Application")
Add the following line also
xln.DisplayAlerts=False
But you avoid this message box from excel.
After you create an instance of excel ie,
Set xln = CreateObject("Excel.Application")
Add the following line also
xln.DisplayAlerts=False
www.easyprograming.com
Make Your Programing Easy
Make Your Programing Easy
![]() |
•
•
•
•
•
•
•
•
DaniWeb Visual Basic 4 / 5 / 6 Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
activation blogger blogs code combo daniweb debugging dell development dreamweaver drivers firefox fix framework games gpl graphics html innovation intel internet key linux microsoft mozilla news open open source open-source opengl operating product programming red hat rss serial software source sun super system tags ubuntu vista wesnoth windows wysiwyg xml xp
- Code 19 error with USB digital camera (Windows NT / 2000 / XP / 2003)
- Filename as a constant? (C++)
- SS tabs (Visual Basic 4 / 5 / 6)
- help me ffix this (C++)
- Some stupid error i cant fix, PLEASE HELP (Java)
- on Ifstream (C++)
- Open source for code for program similar to HyperTerminal (VB.NET)
- please fix the error (C++)
- Spell Check Open Source Code Required (JSP)
- total newb - "passing arg 2 of `strcpy' makes pointer from integer without a cast" (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How to Copy an Excel range into an array
- Next Thread: Open file from listbox


Linear Mode