print sheet 1 of worksheet from Access VBA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cedelmann
    New Member
    • May 2010
    • 2

    #1

    print sheet 1 of worksheet from Access VBA

    I have the following code, which prints a worksheet based on a query to get directory name, and sheet name. It works great except I only want sheet 1.

    Any help on how to modify my code to get sheet 1 would be greatly appreciated.

    code...

    Private Sub Command12_Click ()
    Dim objXL As Object
    Dim xlWB As Object
    Dim mach_name As String
    Dim tool_name As String
    Dim SQL As String
    Dim File_Path As String

    SQL = "Select Machine_and_Too l.mach, Machine_and_Too l.tool from Machine_and_Too l"
    'Open Connection and Run SQL
    Dim dbConnection As New ADODB.Recordset
    dbConnection.Op en SQL, CurrentProject. Connection, adOpenStatic, adLockOptimisti c
    mach_name = dbConnection("m ach").Value
    tool_name = dbConnection("t ool").Value
    File_Path = "G:\Production\ Vacuum Forming\VF Forms\Setup Sheets\" & mach_name & "\" & tool_name & ".xls"

    Set objXL = CreateObject("E xcel.Applicatio n")
    Set xlWB = objXL.Workbooks .Open(File_Path )

    xlWB.PrintOut

    xlWB.Close
    objXL.Quit
    Err:
    Set xlWB = Nothing
    Set objXL = Nothing

    End Sub
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    My excel is a bit rusty, but have you tried to replace:
    Code:
    xlWB.PrintOut
    with
    Code:
    xlWB.Sheets(1).PrintOut
    Welcome to Bytes, please remember to use [Code] . . . [/Code] tags around your code.

    Comment

    • Cedelmann
      New Member
      • May 2010
      • 2

      #3
      Originally posted by TheSmileyOne
      My excel is a bit rusty, but have you tried to replace:
      Code:
      xlWB.PrintOut
      with
      Code:
      xlWB.Sheets(1).PrintOut
      Welcome to Bytes, please remember to use [Code] . . . [/Code] tags around your code.
      I had tried syntax close to this, but obviously it was not correct. Your syntax was, and I appreciate it. Thank you.

      Comment

      Working...