Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Wed Jul 18, 2018 7:30 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How to use the method Excel.Workbooks.Close ?
PostPosted: Sun Jun 03, 2012 9:32 pm 
Offline
User avatar

Joined: Thu Dec 29, 2011 6:46 pm
Posts: 191
Location: Edmonton, AB, Canada
Let see if anybody can help me...
The Open method was successful and now I can Open Excel Files
But I am getting a error when I try to close it. See the code below

Sub Action()
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

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

Exception err As OLEException
MsgBox err.Message
End Sub


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: How to use the method Excel.Workbooks.Close ?
PostPosted: Sun Jun 03, 2012 9:43 pm 
Offline
User avatar

Joined: Thu Dec 29, 2011 6:46 pm
Posts: 191
Location: Edmonton, AB, Canada
It works when I have one workbook open.
But if I have 10 workbooks I want to choose what workbook I want to close.

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.Workbooks.Close
objExcel.Quit

Exception err As OLEException
MsgBox err.Message


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: How to use the method Excel.Workbooks.Close ?
PostPosted: Mon Jun 04, 2012 1:12 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
Off the top of my head, the Workbooks operate as a collection or array

Try this sort of thing:

objExcel.Workbooks(0).Close

objExcel.Workbooks("Fred").Close


Top
 Profile  
Reply with quote  
 Post subject: Re: How to use the method Excel.Workbooks.Close ?
PostPosted: Mon Jun 04, 2012 7:38 am 
Offline
User avatar

Joined: Thu Dec 29, 2011 6:46 pm
Posts: 191
Location: Edmonton, AB, Canada
kermit,

Thank you, it worked.

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.Workbooks(sExcelFileName).Close
objExcel.Quit

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