Autorun Macro on file opening

S

Sha-auto

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
 
B

bawahoo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top