Results 1 to 3 of 3

Thread: Why is this not working?

  1. #1

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Could someone tell me why this is not printing.

    Private Sub Command1_Click()

    Dim O As Object
    Set O = CreateObject("excel.application")
    O.Visible = True
    O.DisplayAlerts = False
    O.Workbooks.Open App.Path & "\Invoice.xls"

    O.ActiveWorkbook.SaveAs App.Path & "\New Workbook.xls"

    O.Range("B3").Value = "test"



    O.ActiveWindow.Sheet1.PrintOut Copies:=1

    O.ActiveWorkbook.Close Savechanges:=False
    O.Quit



    I get an error on this line:

    O.ActiveWindow.Sheet1.PrintOut Copies:=1

    Any Help?

    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

  2. #2
    Frenzied Member Microbasic's Avatar
    Join Date
    Mar 2001
    Posts
    1,402
    It's not working because you don't access a sheet using .sheet1.

    Code:
    Private Sub Command1_Click()
    
    Dim O As New Excel.Application, s As Worksheet
    O.Visible = True
    O.DisplayAlerts = False
    O.Workbooks.Open App.Path & "\Invoice.xls"
    
    O.ActiveWorkbook.SaveAs App.Path & "\New Workbook2.xls"
    
    O.Range("B3").Value = "test"
    
    
    
    Set s = O.ActiveWindow.ActiveSheet
    s.PrintOut Copies:=1
    
    O.ActiveWorkbook.Close Savechanges:=False
    O.Quit
    
    End Sub


    MicroBasic
    Dragon Shadow Trainer

    There is no good or evil in the world...only programmers and fools .

  3. #3

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674

    Oh Yeah!

    Thank you!!

    JO
    "I have not failed. I've just found 10,000 ways that won't work."
    'Thomas Edison'

    "If we knew what it was we were doing it wouldn't be called research, would it?"
    'Albert Einstein'

    VB6

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