+ Reply to Thread
Results 1 to 6 of 6

Vba.excel - problem with "GetObject"

Hybrid View

  1. #1
    Registered User
    Join Date
    03-18-2005
    Posts
    19

    Question Vba.excel - problem with "GetObject"

    Hello, have a problem with recording a small macro
    I need : 1. take some .xls fail; 2.put some data in it 3. save with other name
    Maybe somebedy can said where is a problem in script?
    Thanx.

    Sub TestReport()

    Dim Excelsheet As Object
    Set Excelsheet = GetObject("C:\Book2.xls")

    ExcelSheet.Application.Cells(2, 1) = "111"
    ExcelSheet.Application.Cells(5, 1) = "222"
    ExcelSheet.Application.Cells(9, 1) = "aaa"

    Excelsheet.SaveAs "C:\report_test.xls"
    Excelsheet.Application.Quit
    Set Excelsheet = Nothing

    End Sub

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    Why don't you just open the workbook?

    Dim Excelsheet As Object
    Set Excelsheet = Workbooks.Open("C:\Book2.xls")

  3. #3
    Registered User
    Join Date
    03-18-2005
    Posts
    19
    Quote Originally Posted by Norie
    Why don't you just open the workbook?

    Dim Excelsheet As Object
    Set Excelsheet = Workbooks.Open("C:\Book2.xls")
    Damn! It was so easy!

    Norie great thanx !!

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    No problem.

    By the way I don't think the rest of your code is going to work either.

    As far as I know the Application object does not have a Cells property.

  5. #5
    Registered User
    Join Date
    03-18-2005
    Posts
    19
    Quote Originally Posted by Norie
    No problem.

    By the way I don't think the rest of your code is going to work either.

    As far as I know the Application object does not have a Cells property.
    Actualy, I think so too, but

    the code is working right ! ))

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    I'm wrong.

    The Cells property of the Application object refers to the cells in the active sheet.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1