473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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_Tool.mach, Machine_and_Tool.tool from Machine_and_Tool"
'Open Connection and Run SQL
Dim dbConnection As New ADODB.Recordset
dbConnection.Open SQL, CurrentProject.Connection, adOpenStatic, adLockOptimistic
mach_name = dbConnection("mach").Value
tool_name = dbConnection("tool").Value
File_Path = "G:\Production\Vacuum Forming\VF Forms\Setup Sheets\" & mach_name & "\" & tool_name & ".xls"

Set objXL = CreateObject("Excel.Application")
Set xlWB = objXL.Workbooks.Open(File_Path)

xlWB.PrintOut

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

End Sub
May 19 '10 #1

✓ answered by Cedelmann

@TheSmileyOne
I had tried syntax close to this, but obviously it was not correct. Your syntax was, and I appreciate it. Thank you.

2 1814
TheSmileyCoder
2,322 Expert Mod 2GB
My excel is a bit rusty, but have you tried to replace:
Expand|Select|Wrap|Line Numbers
  1. xlWB.PrintOut
with
Expand|Select|Wrap|Line Numbers
  1. xlWB.Sheets(1).PrintOut
Welcome to Bytes, please remember to use [code] . . . [/code] tags around your code.
May 19 '10 #2
@TheSmileyOne
I had tried syntax close to this, but obviously it was not correct. Your syntax was, and I appreciate it. Thank you.
May 20 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Andrew Poulos | last post by:
If I have an external stylesheet that is @imported into my page and it has an element that looks like this: * html td { font-style: italic; } how can I use javascript to change the font...
9
by: Edward S | last post by:
I budget for a Project in an Excel sheet as illustrated below. The months below are usually a 2 year period i.e. 24 months, though it could be over 24 months depending upon a Project. I then...
0
by: ImraneA | last post by:
Hi there Hope this helps others Public Function Export_Excel_10(dblocation As Variant) On Error GoTo Err_Export_Excel_10 Dim x1 As Excel.Application Dim excelwbkXL As Object
0
by: Ric#k | last post by:
I want to print several MS Access reports already written for our legacy (VB6) system. into the system we are now devloping in C# and VB.NET. Can you tell me the references I need and what...
2
by: Dean Slindee | last post by:
Anybody written code in VB.NET to: 1) show a print preview window of reports already written and stored in an Access 2002 database; or 2) execute the print of a report stored in an Access 2002...
2
by: RICHARD BROMBERG | last post by:
I wrote a small Access application that accepts a City Name and a Street Name and runs a Query based on them . I want to create an Excel Spread sheet that contains all the matches found by the...
5
Zerin
by: Zerin | last post by:
I have to develop a database in access and VB 2005 will be in front view. Some results are send to this software in .csv format and .jpg format and I have to store it in the database.Now, for .csv...
2
by: saddist | last post by:
Hello, I have and excel sheet with fields: Name | Surname | Dept. When I execute the following code, it imports 16 empty rows + filled ones DoCmd.TransferSpreadsheet acImport = 0,...
3
by: inepu | last post by:
I have some excel sheets that I would like to manage in access. I've created the access tables and relationships; the excel sheet is only one table and with duplicate data, I'd like to make sure that...
0
by: satenova | last post by:
Hello Friends, I am newbie when it comes to vb.net and i need to import excel sheet into access db using vb.net application. Here is the code i use for now to upload excel sheet and it works...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.