Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Using VB to manipulate Excel

Posted on 2000-05-16
7
Medium Priority
?
206 Views
Last Modified: 2010-05-02
I asked a question a while back, and I know how to add values to cells, etc, but I want to know the following:

1) How do I copy a sheet and rename it using VB?

2) How can I save under a different filename?

3) How can I do a Application.Quit without having it ask me if I want to save my changes?

Basically I have a workbook with a template framework, I want a VB 6.0 app to fill in values, the 'save as' it to a different name.

Anyone?
0
Comment
Question by:edskee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 1

Expert Comment

by:Chrynoble
ID: 2814995
This answer assumes you know how to create an excel object.

1)
 xlapp.worksheets(yoursheet).copy Before:=Sheets(thesheet)
' You can also use the keyword after here

2)
 xlapp.activeworksheet.save as "C:\Whatever"

3)
 xlapp.displayalerts = false
 ' Add the above line before quiting.
0
 
LVL 1

Expert Comment

by:Chrynoble
ID: 2815000
Sorry forgot one
1)
 xlapp.activesheet.name = "thename"
 ' You may also what to use "thename.xls"
0
 
LVL 1

Expert Comment

by:Chrynoble
ID: 2815003
Sorry, I am brain dead today. You only want to use "thename.xls" if you are renaming the workbook, not the sheet.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Accepted Solution

by:
calacuccia earned 200 total points
ID: 2815261
2) Just a syntax correction (as Chrynoble is brain dead ;-)):

xlapp.ActiveWorksheet.SaveAs "C:\Whatever"

(no space between "Save" & "As")

3) A better way to disable the 'Save Changes?" dialog is to set the Saved property of all open workbooks to Yes.
xlapp.DisplayAlerts = False will remain that way the next time you (or someone else who would like to see that alert) opens Excel.
In that cas, put this before the xlapp.Quit line:

For Each wb in xlapp.Workbooks
wb.Saved=True
Next wb

If you only have the single workbook opened:

xlapp.ActiveWorkbook.Saved = True

Good Luck
Calacuccia


0
 
LVL 6

Expert Comment

by:Marine
ID: 2815453
Here is what i tried.

say you already have values in your worksheet. Then you want to copy these values into another sheet, it will create another sheet for you.

so what you do is this.
'xlSheet is Excel.WorkSheet
'xlBook is Excel.WorkBook
when using Copy Method you have there 2 parameters you might want to use them.If you want to copy certain rows only. This will copy an entire WorkSheet.

xlSheet.Copy
xlSheet.SaveAs FileName:="YourFile.xls"
xlBook.Close SaveChanges:=False
0
 
LVL 2

Author Comment

by:edskee
ID: 2815573
Awesome, just about all I was looking for. Can you reccomend a website that has this info? Every time I try to do something new I gotta ask another question on here :)

0
 
LVL 17

Expert Comment

by:calacuccia
ID: 2816330
I don't know or use any websites for this kind of stuff. Just practice, and participation on this site (try to comment on questions too, specificically in the MSOffice section if you'll need to work with Excel a lot).

Calacuccia
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question