LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Use a xla file to look in xls file when opening

Hello!

I am trying to write an xla-file that runs a macro when a xls-file is
opening (this is actually my first xla-file)
Then it should look in the xls sheet and if the cells(1,1) is "L" then it
should format the xls sheet page setup.

The problem is that the xls filename and sheetname isn't known. And I can't
make it to work to look in cells in the xls-file.
Here is the code in the xla-file (works if I add it to an xls-file):

Private Sub Workbook_Open()
If Cells(1, 1) = "Orientation L=Landscape" And Cells(2, 1) = "Fit A4 width
TRUE=Fit" Then
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup
If Cells(1, 2) = "L" Then .Orientation = xlLandscape
.Zoom = False
If Cells(2, 2) = "TRUE" Then .FitToPagesWide = 1: .FitToPagesTall =
100
End With
End If
End Sub

The error message I get when I opens the xls-file is:
Run-time error '1004':
Method 'Cells' of object '_Global' failed

It seems like the workbook (xls) isn't available or in focus when the code
is running.
Could anyone help me to solve this?
Regards Magnus


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Opening file in Excel 2003 opens multipule instances of same file Ed_B Excel Discussion (Misc queries) 1 June 21st 07 07:10 PM
File:1 and File:2 -- Double Files when Opening One File dallin Excel Discussion (Misc queries) 1 January 25th 07 02:53 AM
opening an excel file opens a duplicate file of the same file skm Excel Discussion (Misc queries) 1 December 7th 05 05:52 PM
Error:Invalid File format,while opening an Excel Template file Saurabh Excel Programming 1 January 17th 05 07:15 AM


All times are GMT +1. The time now is 06:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"