LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default activate a workbook without using its filename?

ThisWorkbook refers to the workbook with the code, so if the code is in N
form.xls, then replace it with ThisWorkbook.

--
Regards,
Tom Ogilvy


"Jon" wrote in message
ups.com...
I have a macro that runs automatically. The computer is in an
environement where I don't want users to be able to modify the
spreadsheet or the code so I have the sheets and workbook protected.
The only workaround I can see that would hinder my VBA code is if the
user changed the actual filename of my spreadsheet (N form.xls). My
code is below...

Sub Archive()

Dim rng1 As Range
Dim rng2 As Range

Workbooks.Open "C:\Documents and
Settings\username\Desktop\Archivefile.xls"

Workbooks("Archivefile").Sheets("Archive").Unprote ct
Password:="password"

Set rng1 = Workbooks("Archivefile").Sheets("Archive") _
.Cells(Rows.count, 1).End(xlUp)(2).Offset(3, 0)

Workbooks("N Form").Activate

Sheets("Form").Select
Range("A3:B5").Copy
rng1.PasteSpecial xlFormats
rng1.PasteSpecial xlValues

Set rng2 = Workbooks("Archivefile").Sheets("Archive") _
.Cells(Rows.count, 1).End(xlUp)(2).Offset(1, 0)

Workbooks("N Form").Activate

Sheets("Form").Select
Range("A18:B42,F18:F42,G18:H42").Copy
'rng2.PasteSpecial xlFormats
rng2.PasteSpecial xlValues

Workbooks("Archivefile").Sheets("Archive").Protect
Password:="password"

Application.CutCopyMode = False
Workbooks("Archivefile").Save
Workbooks("Archivefile").Close

'Workbooks("N Form").Sheets("Form").PrintOut Copies:=1

End Sub


You can see I use Workbooks("N Form").Activate to bring up the
workbook that contains my 'Archive' macro. My question is, can I
activate workbooks without referring to their filename? If this isn't
possible, I suppose some sort of protection against renaming the file
in Windows is in order...



 
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
Activate Different workbook? John Excel Programming 6 August 1st 05 05:51 PM
Workbook.activate Jeff Excel Discussion (Misc queries) 1 December 13th 04 10:22 PM
Activate Other Workbook pauluk[_37_] Excel Programming 16 April 20th 04 07:02 PM
Activate Workbook Molly Johnson Excel Programming 1 February 10th 04 05:09 PM
How to activate a file when the filename is represented by a string variable news.sintef.no Excel Programming 4 February 6th 04 02:17 PM


All times are GMT +1. The time now is 09:22 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"