473,394 Members | 1,734 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,394 software developers and data experts.

OLE automation: Excel Template question

As a novice VBA programmer, I have a problem with a routine written as
a click procedure from a form to open an Excel template, insert some
information, print, and (ideally) return control back to the form. The
problem is only in that I don't want to answer the question from Excel
"Do you want to save (y/n):". I just want to print the sheet. Can I
do this in such a way that excel will not prompt me to save? I don't
see any alternative but to unload the form, and that is what causes the
prompt to save. I'm sure there is a better way to do this, but as I
said, I'm new to this stuff. Any help is appreciated. Code appears
below.

Craig
cu****@hotmail.com

Option Compare Database
Dim xlObject As Object ' Declare variable to hold the reference to the
Excel Object.

Private Sub AutomateExcel_Click()
'On Error GoTo Err_AutomateExcel_Click

'Create an object for Excel
Set xlObject = CreateObject("excel.application")

'Make the Excel application visible
xlObject.Visible = True
Set xlBook =
xlObject.Workbooks.Add("\\Termsrvr\tshome\******** \********\Dev\TS.xlt")
'Activate the worksheet, select the range, activate a cell in the range
xlObject.Worksheets("Sheet1").Activate
xlObject.ActiveSheet.Range("B5").Select
xlObject.ActiveSheet.Range("B5").Activate

'Set focus to LNF on Access form
LNF.SetFocus
'Place the LNF in the active cell.
xlObject.ActiveCell.Value = UCase(LNF.Text)

xlObject.ActiveSheet.Range("F5").Select
xlObject.ActiveSheet.Range("F5").Activate

'Set focus to TSEmpLocation on Access form
TSEmpLocation.SetFocus
'Place TSEmpLocation in the active cell.
xlObject.ActiveCell.Value = TSEmpLocation.Text

xlObject.ActiveSheet.Range("I5").Select
xlObject.ActiveSheet.Range("I5").Activate

'Set focus to TSEmpNum on Access form
TSEmpNum.SetFocus
'Place TSEmpNum in the active cell.
xlObject.ActiveCell.Value = TSEmpNum.Text

xlBook.PrintOut
On Error Resume Next
xlObject.UserControl = True

Exit_AutomateExcel_Click:
xlObject.Quit
Set xlBook = Nothing
Set xlObject = Nothing
Exit Sub
Err_AutomateExcel_Click:
MsgBox Err.Description
Resume Exit_AutomateExcel_Click

End Sub

Private Sub Detail_Click()

End Sub

Private Sub Form_Load()

End Sub

Jan 16 '06 #1
2 2967
All you need to do is insert this line when you are all done with the
workbook:

xlBook.Close False

The "false" value is for the SaveChanges parameter...

Jay Taplin MCP

Jan 16 '06 #2
Just what I needed - Thank you so much

Jan 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jimmer | last post by:
I've got what should be an easy automation problem, but the solution simply isn't coming to me. I've got several public variables set up for automation as follows: Public gappExcel As...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
3
by: Stephen Brooker | last post by:
Hi all, Just playing around a MS how-to sample to work with an Excel file from within C#. Everything is fine and I understand it OK, however when Excel and the application are closed, there is...
6
by: a.theil | last post by:
Please help! I need a simple excel automation, just 2 write some files into excel. I do: Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As...
12
by: Steve | last post by:
I've been building an application that will merge fields in a text file with a word template, save the resulting word file out to the user's hard drive, and then email the file as an attachment. ...
4
by: Keith Wilby | last post by:
How controllable from Access VBA is Excel? I'm currently using automation to dump 2 columns of data into an Excel spreadsheet so that the end user can create a line graph based on it. Could the...
1
by: webgirl | last post by:
Hi everyone, I have a weird problem with some Word/Excel automation code that I run from Access (not sure if I should therefore post this in the Access forum..? Thought I'd try here first) ...
10
by: Esmael | last post by:
Hi to all, /*****************************/ OS-WIn XP SP2 VB6 SP6 /*****************************/ Is their anyone who can help me with this: Source code written on VB6.
0
by: xrxst32 | last post by:
Hello there, I have some doubts about the best practice for using COM automation, the Runtime Callable Wrapper (RCW) and Marshal.ReleaseComObject. So the question is/are: Do I need to release...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.