Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Mar 30, 2020 11:35 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: SaveAs a Excel File
PostPosted: Tue Jun 05, 2012 7:31 am 
Offline
User avatar

Joined: Thu Dec 29, 2011 6:46 pm
Posts: 191
Location: Edmonton, AB, Canada
We are almost there, we have now know how to open and close a specific Excel File.
Now how to Save and SaveAs a file that was open and modified its contents ?

Dim objExcel As ExcelApplication
Dim objExcelWorkbook As ExcelWorkbooks
Dim objExcelWorksheet As ExcelWorksheets
Dim sExcelFilePath As string
Dim sExcelFileName As string

sExcelFilePath = "C:\Users\Me\Desktop"
sExcelFileName = "myExcelFile.xls"

objExcel = new ExcelApplication
objExcel.visible = true

// SaveAs do not exit so we have to do something else
// The code below will not work, there no method save or saveas
// Does anyone suggest something ?

objExcel.Workbooks.SaveAs(sExcelFilePath+"\"+sExcelFileName)


Exception err As OLEException
MsgBox err.Message

_________________
Regards,
TomazVDaSilva


Clean Code: Robert C. Martin
It is not the language that makes programs appear simple.
It is the programmer that make the language appear simple!


Top
 Profile  
Reply with quote  
 Post subject: Re: SaveAs a Excel File
PostPosted: Tue Jun 05, 2012 7:40 am 
Offline

Joined: Wed May 20, 2009 4:43 pm
Posts: 958
TomazVDaSilva wrote:
We are almost there, we have now know how to open and close a specific Excel File.
Now how to Save and SaveAs a file that was open and modified its contents ?

objExcel.Workbooks.SaveAs(sExcelFilePath+"\"+sExcelFileName)

I haven't worked with Excel in RB, but you are referencing the workbooks collection here, not a specific workbook.

You probably want something like this:
objExcel.Workbooks.Item(WorkbookNameOrIndex).SaveAs(sExcelFilePath+"\"+sExcelFileName)

_________________
RB 2009r4 Windows XP


Top
 Profile  
Reply with quote  
 Post subject: Re: SaveAs a Excel File
PostPosted: Tue Jun 05, 2012 9:18 am 
Offline
User avatar

Joined: Thu Dec 29, 2011 6:46 pm
Posts: 191
Location: Edmonton, AB, Canada
markwalsh, thank you !

I will test your information below, later when I get home...

objExcel.Workbooks.Item(WorkbookNameOrIndex)._

SaveAs(sExcelFilePath+"\"+sExcelFileName)


Regards,
Tomaz

_________________
Regards,
TomazVDaSilva


Clean Code: Robert C. Martin
It is not the language that makes programs appear simple.
It is the programmer that make the language appear simple!


Top
 Profile  
Reply with quote  
 Post subject: Re: SaveAs a Excel File
PostPosted: Tue Jun 05, 2012 7:16 pm 
Offline
User avatar

Joined: Thu Dec 29, 2011 6:46 pm
Posts: 191
Location: Edmonton, AB, Canada
markwalsh, it did work, see the code below:

Dim objExcel As ExcelApplication
Dim objExcelWorkbook As ExcelWorkbooks
Dim objExcelWorksheet As ExcelWorksheets
Dim sExcelFilePath As string
Dim sExcelFileOldName As string
Dim sExcelFileNewName As string

sExcelFilePath = "C:\Users\Me\Desktop"
sExcelFileOldName = "myExcelFile.xls"
sExcelFileNewName = "myExcelFileNewName.xls"

objExcel = new ExcelApplication
objExcel.visible = true

objExcel.Workbooks.Item (sExcelFileOldName). _
SaveAs (sExcelFilePath+"\"+sExcelFileNewName)


Exception err As OLEException
MsgBox err.Message

_________________
Regards,
TomazVDaSilva


Clean Code: Robert C. Martin
It is not the language that makes programs appear simple.
It is the programmer that make the language appear simple!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group