Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel obj.save

Status
Not open for further replies.

vzachin

Technical User
Feb 10, 2006
305
US
hi,
i have the following code that inputs data onto an excel worksheet.
i can save the sheet, but when i open up the file, i have to go to Window,Unhide,UnhideWorkbook in order to view the file.
How can i save the file without hiding it?

Here's a sample of the code

Code:
Sub Main()
' Get the main system object
	Dim Sessions As Object
	Dim System As Object
	Set System = CreateObject("EXTRA.System")	' Gets the system object
	Set Sessions = System.Sessions
        Dim obj as object
        Dim objWorkbook as object
        Set obj=CreateObject("Excel.Application")
        Set obj= getobject("C:\test.xls") 
        set objWorkbook=obj.Worksheets("Sheet1")      
   	Dim Sess0 As Object
	Set Sess0 = System.ActiveSession
        objWorkBook.Range("A4").value   = "GOODBYE"
        Obj.save
        set objWorkBook = Nothing
        set objExcel = Nothing   
End Sub


thanks
zach
 
I'm not sure why it's defaulting to hidden, but have you tried adding objWorkBook.Visible = True?
 
Manually open the Excel spreadsheet, unhide and save. Run the following code.

Code:
Sub Main()
   Dim Sessions As Object, System As Object, Sess0 As Object
   Dim xl As Object, xl_workbook As Object, xl_sheet As Object
   Dim iRows As Long, iCols As Long

   Set System = CreateObject("EXTRA.System")
   Set Sessions = System.Sessions
   Set Sess0 = System.ActiveSession

   Set xl = CreateObject("Excel.Application")
   Set xl_workbook = xl.Workbooks.Open("C:\test.xls")
   Set xl_sheet = xl_workbook.Worksheets("Sheet1")

   'iRows = Sess0.Screen.Rows
   iCols = Sess0.Screen.Cols

   '                            Grabs line 2 on terminal
   xl_sheet.Range("A3").Value = Sess0.Screen.GetString(2, 1, iCols)
   xl_sheet.Range("A4").Value = "GOODBYE"

   xl_workbook.Save
   xl_workbook.Close

   Set xl_sheet = Nothing
   Set xl_workbook = Nothing
   Set xl = Nothing
   Set Sess0 = Nothing
   Set Sessions = Nothing
   Set System = Nothing
End Sub
 
Hi Skie & WinBlowsME,

Thanks for the replies.

objWorkBook.Visible = True didn't work.

However, the coding from WinBlowsMe works for me. i don't understand why it works and the difference between your code and mine. but for sure, i'll be using yours from now on.

thanks again to both of you

zach

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top