Results 1 to 4 of 4

Thread: could someone look at these few lines of code please ...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    UK
    Posts
    300
    I am trying to open an existing spreadsheet and add a few extra lines then close the spreadsheet.

    Private Sub Command3_Click()
    Dim spreadsheetname As String

    Dim objXLS As New Excel.Application

    spreadsheetname = "c:\vbstuff\book3.xls"

    With objXLS
    .Workbooks.Open spreadsheetname



    Rows("1:1").Select
    Selection.Insert Shift:=xlDown
    Selection.Insert Shift:=xlDown
    Range("F1").Select
    ActiveCell.FormulaR1C1 = "xxx"
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "xxx"
    Range("F3").Select
    ActiveCell.FormulaR1C1 = "xxx"
    Range("F4").Select
    ActiveCell.FormulaR1C1 = "xxx"
    Range("F7").Select

    End With

    Set objXLS = Nothing
    MsgBox "finito"


    End Sub

    I want to look and see if it has done as I asked. But when I open the excel ss I get this message.
    "book3.xls is already open , reopening it will discard any changes do you want to reopen "

    I dont think I am releasing the spreadsheet again in my code , how do I do this ? . I want the code to run, add the extra data to the ss then when the code is finnished I wish to then open excel , open my workbook and see the changes without any hassle

    cheers
    Resistance is futile

  2. #2
    Hyperactive Member mikef's Avatar
    Join Date
    Jun 2000
    Location
    Beach bound...
    Posts
    510
    I see you called workbook.Open.

    Is there a similar command to close the workbook...say:

    workbook.close

    or something to that nature. That seems to be the only problem with the code you have posted.

    hope it helps.
    "If I had known it was going to be that kinda party, I would have stuck my disk in the mash potatos!"

  3. #3
    Frenzied Member Technocrat's Avatar
    Join Date
    Jan 2000
    Location
    I live in the 1s and 0s of everyones data streams
    Posts
    1,024
    You need to save it then quit.

    .saveas "path\filename"
    .application.quit
    MSVS 6, .NET & .NET 2003 Pro
    I HATE MSDN with .NET & .NET 2003!!!

    Check out my sites:
    http://www.filthyhands.com
    http://www.techno-coding.com


  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    UK
    Posts
    300

    thanks

    thanks dude , that was it , it always helps to have another pair of fresh eyes looking at your code.

    thanks
    Resistance is futile

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width