ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Autorun Macro on file opening (https://www.excelbanter.com/excel-programming/314846-autorun-macro-file-opening.html)

Sha-auto[_2_]

Autorun Macro on file opening
 

Hi All,
Big Thank-you for your help. I found when I used Workbook_open i
simple opened the file - it didn't run the macro as well. I found
techo at work and he said to try "Sub Auto_Open()". And this worke
however I get the following error - " filename.csv is already.
Reopening will cause any changes you made to be discarded. Do you wan
to reopen filename.csv? " -
if you reply YES then the macro changes are undone, if you reply NO th
file is exactly how I want it to Open. However I would like it with-ou
this msg interaction.

Does anyone understand why I would get this reOpening msg ? if so, ho
can I get rid of it?

This is my code, I'm a real beginner at VB, so basically kno
nothing... I am however, an automation programmer and are learnin
slowly about Excel.
Sub Auto_Open()
'
' Macro1
' Macro recorded 27/10/2004 by me'
ActiveWorkbook.Save
ChDir "\\servername\test"
Workbooks.Open Filename:="\\servername\test\filename.csv"
Cells.Select
Cells.EntireColumn.AutoFit
Range("B:B,K1,K:K").Select
Range("K1").Activate
ActiveWindow.LargeScroll ToRight:=2
Range("B:B,K1,K:K,S:S").Select
Range("S1").Activate
ActiveWindow.LargeScroll ToRight:=2
ActiveWindow.SmallScroll ToRight:=-24
Selection.NumberFormat = "0"
ActiveWindow.LargeScroll ToRight:=-3
Columns("D:D").Select
ActiveWindow.LargeScroll ToRight:=2
ActiveWindow.SmallScroll ToRight:=1
Range("D:D,T:T,W:W").Select
Range("W1").Activate
ActiveWindow.SmallScroll ToRight:=9
Range("D:D,T:T,W:W,AH:AH").Select
Range("AH1").Activate
ActiveWindow.SmallScroll ToRight:=5
Range("D:D,T:T,W:W,AH:AH,AJ:AJ").Select
Range("AJ1").Activate
ActiveWindow.SmallScroll ToRight:=7
Selection.NumberFormat = "$#,##0.00"
ActiveWindow.LargeScroll ToRight:=-5
Columns("F:F").Select
ActiveWindow.SmallScroll ToRight:=6
Range("F:F,L:L").Select
Range("L1").Activate
ActiveWindow.SmallScroll ToRight:=8
Range("F:F,L:L,U:U,V:V").Select
Range("V1").Activate
ActiveWindow.SmallScroll ToRight:=7
Range("F:F,L:L,U:U,V:V,AC:AC").Select
Range("AC1").Activate
ActiveWindow.SmallScroll ToRight:=6
Range("F:F,L:L,U:U,V:V,AC:AC,AM:AM").Select
Range("AM1").Activate
ActiveWindow.SmallScroll ToRight:=7
Selection.NumberFormat = "dd/mm/yyyy;@"
ActiveWindow.LargeScroll ToRight:=-5
Range("A1").Select
ActiveSheet.Protection.AllowEditRanges.Add Title:="LockColumns"
Range:=Range( _
"V:W,AL:AQ")
ActiveSheet.Protect DrawingObjects:=False, Contents:=True
Scenarios:= _
False, AllowFormattingCells:=True
AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True
AllowInsertingRows _
:=True, AllowInsertingHyperlinks:=True
AllowDeletingColumns:=True, _
AllowDeletingRows:=True, AllowSorting:=True
AllowFiltering:=True, _
AllowUsingPivotTables:=True
End Su

--
Sha-aut
-----------------------------------------------------------------------
Sha-auto's Profile: http://www.excelforum.com/member.php...fo&userid=1570
View this thread: http://www.excelforum.com/showthread.php?threadid=27233


bawahoo[_5_]

Autorun Macro on file opening
 

Make sure you turn the Macro Security to LOW in excel. This is the onl
way the Private Sub Workbook_Open() will work on open without any use
interaction

--
bawaho
-----------------------------------------------------------------------
bawahoo's Profile: http://www.excelforum.com/member.php...fo&userid=1510
View this thread: http://www.excelforum.com/showthread.php?threadid=27233



All times are GMT +1. The time now is 04:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com