Run Sub When Worksheet Opens
Apr 24, 2007
I have a date displayed in a controlbutton caption that fails to refresh each time the worksheet is opened.
Q1: How do I run the sub below each time the user opens the worksheet?
Q2: Is there a better way to clear the contents of a textbox?
Private Sub ClearForm_Click()
ActiveSheet.Unprotect
ActiveSheet.Range("C4,C6,C8,F4,F6,F8,F25").ClearContents
ActiveSheet.Range("I4").Value = 0
ActiveSheet.Shapes("Text Box 12").Select
Selection.Characters.Text = ""
MailDate.Caption = Range("H11").Value
ActiveSheet.Range("F4").Select
ActiveSheet.Protect
End Sub
View 9 Replies
ADVERTISEMENT
Feb 1, 2007
I have worksheet with a macro and currently if I run the macro using the play button and then select the macro it runs fine but what i want it to do is run when i open the workbook automatically.
View 3 Replies
View Related
Mar 4, 2009
I have to questions...
1. I have a form that I setup to open when my excel db is opened. How do I get the excel db to minimize or hide so that only the form is open.
2. How to I add minimize and maximize buttons to the forms I have created?
View 9 Replies
View Related
May 18, 2009
I have a workbook where the sheets are all protected and I want to stop users scrolling up or across beyond the limits of the input areas.
I have used the following code (or variations of)...
Private Sub Worksheet_Activate()
Me.ScrollArea = "A1:G32"
End Sub
This works fine except that when I first open the workbook, the first sheet displayed can still be scrolled. As soon as you move to another sheet and then back again, it is then OK.
It appears that the Worksheet_Activate code does not execute when the workbook is first opened.
How do I get round this?
View 9 Replies
View Related
Nov 6, 2009
I currently have the following code that copies a range opens notepad pastes the range opens save dialog and types the file name. The problem I have is with overwriting the existing file.
Range("A1:A202").Select
Selection.Copy
Shell "notepad.exe", vbNormalFocus
SendKeys "^V"
SendKeys "^s"
SendKeys "Total_IEDs_Hour_Of_Day_2009.xml"
SendKeys "{TAB}"
SendKeys "a"
SendKeys "{ENTER}"
Everything works fine to this point. Then it opens the do you want to overwrite dialog and I cant get it to hit yes.
View 9 Replies
View Related
Oct 4, 2008
How do I run this I can not get it to work I keep getting errors this is the way I have it for now.
Private Sub ThisWorkbook_Open()
MY_MONTH = Month(Now()) + 5
With Sheets("Master List")
.Unprotect ("123")
.Columns("A").Locked = False
.Columns("A").Hidden = True
.Columns("T:IV").Hidden = True
.Rows("265:65536").Hidden = True
.Columns("E:Q").Locked = False
.Columns("E:Q").Hidden = True
.Columns(MY_MONTH).Hidden = False
.Columns(MY_MONTH - 1).Hidden = False
.Columns(MY_MONTH - 1).Locked = True
Dim ws As Worksheet
For Each ws In Sheets([{"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC","2008","Read Me","Record"}])
With ws
.Protect ("123")
End With
Next
End Sub
Compile error: Expected End With
View 9 Replies
View Related
Dec 24, 2008
When I double click an excel spreadsheet in windows explorer it opens spreadsheet then closes it then opens it again.
This doesnt happen if I have an instance of excel already running.
I thought it might be to do with file association and the open with option.
View 9 Replies
View Related
May 3, 2014
I have a project were i have to make a macro and place in a workbook such that as soon as i open that excel file
1. excel workbook is opened in New Excel window
2. Ribbon is hidden for this new window.
So when user closes this excel window there is no problem with other workbook ribbon, as there are open in different window
I have tried with code stated below it hides the ribbon but new excel window is not open
Private sub Workbook_open()
Application.ExecuteExcel4Macro "Show.toolbar(""Ribbon"",False)"
End Sub
View 2 Replies
View Related
Sep 14, 2009
This is a follow-on to a great solution provided by Shg and Rylo. Here is the link. http://www.excelforum.com/excel-prog...new-sheet.html
My users have run in to an interesting issue with the file. Each time the files opens it has the same 5 questions selected. What I need the code to do is randomize the questions each time the sheet is opened. Basically, the users seem to have a problem using the "make quiz" button, so they have requested that I make sure that the quiz randomizes each time it is opened.
View 7 Replies
View Related
Jan 31, 2010
I would really like to know if there is a way that when my workbook opens if the following can happen?
- Not display the tabs (NOT "HIDE" the sheets, just not be able to view the tabs themselves)
- Go to full screen (not display ribbon)
View 6 Replies
View Related
Dec 19, 2007
I have a spreadsheet that can't be password protected but this doesn't mean just anyone should be accessing it. Is there a way to record who opens it and when? Ideally I could place some code into the spreadsheet that recorded on a sheet who has opened it and when. This will detract certain nosy people from accessing it!
View 9 Replies
View Related
Jul 16, 2008
My workbooks contains 2 worksheets with data and autofilters on for each column in use.
When my workbook opens I am trying to reset the autofilters of each worksheet in the workbook and to filter the data according to one criteria in one column.
This is what I have that works to reset each worksheet but I haven't been able to figure out how to subsequently filter each worksheet.
Private Sub Workbook_Open()
Application.ScreenUpdating = False
For Each w In Worksheets
w.Unprotect
If w.FilterMode Then w.ShowAllData
w.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFiltering:=True
Next w
Application.ScreenUpdating = True
End Sub
The autofilter sits in A3 to N3 and I am trying to filter according to column M (i.e. 13th column)
View 9 Replies
View Related
Oct 27, 2006
I've created an add-in that runs a simple macro. The problem I have is that when I run the add-in it opens the workbook I originally created it from - is this what I should expect it to do? How do I stop this from happening?
Also, do I need to have the workbook from which I created the add in located in the same place on every machine I want to use the add in on? At the moment if I move the original workbook the add-in won't work.
View 9 Replies
View Related
Feb 28, 2007
I have a function which selects a file and opens it.It is part of a code.
Sub Cpy()
' Macro recorded 1/16/2007 by PZCHFR
Set PresentWorkBook = ActiveWorkbook
FSel
Findlastusedrow
Cpy_Name
getmonth
End Sub
Function FSel()
filetoopen = Application. GetOpenFilename("Document Files (*.xls), *.xls", 1)
'Workbooks.Open Filename:=filetoopen
'Set OpenedWorkBook = Application.Workbook(filetoopen)
Set OpenedWorkBook = Workbooks.Open(Filename:=filetoopen)
End Function
When the user does not select any file and clicks "cancel" in the dialog box,this gives me runtime error .How do i make the code correct so as to handle the case where there is no file selected.
View 4 Replies
View Related
Sep 28, 2013
I want to run a VBA macro when Excel opens if and only if the file name contains a specific string or if and only if the worksheet name contains a specific string. The file only contains one worksheet. For example, if the file name contains the string "SalaryData" or the sheet name contains "SalaryData", then I want to run a VBA macro to delete some of the confidetial information. Idealy, this would be done as the file is opening before it is displayed.
View 1 Replies
View Related
Dec 12, 2012
In the last couple of weeks my copy of Excel 2010 has started acting strange. Now when I double click an xls or xlsx file in Windows Explorer, it tries to open a new instance of Excel, whic means that it tries to reopen Personal.xlsm and Personal.xlsb, and finds they are already open, so it gives me an error message. Previously it perfectly happily opened the document in another window in the same instance, which is presumably much more memory efficient quite apart from the file locking problem mentioned. How do I get it back to the way it was before? Is this another of MS's famous overnight downgrades?
View 2 Replies
View Related
Jul 29, 2009
I'm creating a userform for editing membership records of a small organisation. So I want the focus to default to textbox tboxFind which is used for searching the data.
I've put tboxFind first in the tab order, and in subroutine Userform_Initialize, the last line is tboxFind.SetFocus
Using Excel2000 on Windows Vista, it works OK.
Opening the same workbook in Excel2000 on WinXP, no textbox has the focus when the form opens, but once the user has started to use the form, the focus defaults back to tboxFind, as it should.
So why is the focus not where it should be when the form opens in WinXP?
View 11 Replies
View Related
Nov 24, 2009
I need to stop the calculations when the workbook opens. I have tried
View 2 Replies
View Related
Jan 6, 2010
I have a workbook on a share drive that is used by multiple people. In the event that someone leaves the workbook open after using it, I have a timer function that pops up a splash screen after 4 minutes of inactivity which states, "This workbook will close in 1 minute if there is no further activity". If there is no further activity in that minute, the workbook closes.
The code works fine...unless the workbook is manually closed in that minute between the splash screen and when the timer would have closed the workbook. If that happens, the workbook closes normally and then briefly reopens and closes a minute later when the timer would have closed the workbook. Is there any code to prevent this?
View 4 Replies
View Related
Mar 7, 2012
I have the following code in a module that I would like to initiate when the workbook opens:
Code:
Private Declare Function GetComputerName Lib "kernel32" _
Alias "GetComputerNameA" ( _
ByVal lpBuffer As String, _
ByRef nSize As Long) As Long
Public Property Get ComputerName() As String
[Code] ........
In a worksheet, I have =compname() in cell A1 and =hdserialnumber() in A2. What is the trick to make the values in these cells appear as soon as the worksheet opens?
View 2 Replies
View Related
Mar 30, 2012
I need a code that will automatically run my first macro. The first macro already calls all the others. I just need everything to run as soon as someone opens the file.
View 3 Replies
View Related
Feb 18, 2013
I have the following macro which basiclly acts as a refresh button on a read only sheet:
Code:
Sub CloseMe()
Application.OnTime Now + TimeValue("00:00:05"), "OpenMe"
ThisWorkbook.Close SaveChanges:=True
End Sub
Sub OpenMe()
End Sub
The sheet is read only as it is used by many people and it prevents them damaging the sheet. The sheet is updated regularly and as many people who use the sheet have little excel knowledge a refresh button was required. The macro is attached to a button that when clicked, it closes the sheet, then reopens it meaning any updates I add to the sheet can then be seen by everyone else once they click the button - much like 'Refresh'.
So, the code above works fine. Click the button, the sheet closes, 5 seconds later reopens. However, when the sheet reopens, any other excel sheets that are open seem to be at the front and the sheet that has been 'reopened' is behind them. Is there anything I can do to make the macro not only close and reopen the sheet, but when it does reopen, bring it to the front so that it is visible straight away without having to click Window and then select the appropriate sheet?
View 1 Replies
View Related
May 2, 2014
I have a project were i have to make a macro and place in a workbook such that as soon as i open that excel file
1. excel workbook is opened in New Excel window
2. Ribbon is hidden for this new window
i have tried with code stated below it hides the ribbon but new excel window is not open
Private sub Workbook_open()
Application.ExecuteExcel4Macro "Show.toolbar(""Ribbon"",False)"
End Sub
View 1 Replies
View Related
Feb 21, 2007
i implement DTPicker inside a userform in my pc ... but when i open the userform in other pc there's an error saying could not found DTPicker ... when i reopen it in the pc that i've made the userform the DTPicker is no longer there and i had to redo the same thing over and over again when others opens it in other pc.
View 4 Replies
View Related
Oct 19, 2009
I have a VB problem, and it's driving me nuts.
Whenever I run a macro on excel the Microsoft VB editor opens and shows me what the macro looks like. It also runs the macro.
Now, I would very much like it to keep running macros, but I really don't need to see my code every time. It gets really annoying, and I need to run about 40 or 50 different macros on one sheet. How can I make it go away?
PS! It's Excel 2007 for students, Norwegian version.
View 9 Replies
View Related
Jun 4, 2006
In the following code, What do I need to add to allow the selected file to open when I click on it? I have a drop down menu that lists my .xls files.....as of now when I choose a file nothing opens.
Sub Auto_Close()
On Error Resume Next
Application. CommandBars("Patient List").Delete
On Error Goto 0
End Sub
'================================
Sub Auto_Open()
Dim cb As CommandBar
Dim ctrl As CommandBarControl
On Error Resume Next
Application.CommandBars("Patient List").Delete
On Error Goto 0
View 3 Replies
View Related
Dec 20, 2006
I was wondering if you can make a popup open when a user opens a spreadsheet. I have some templates i made and users continue to make the same mistakes. I was hoping to add a form/pop so when the file was opened a popup would come up with reminders. Once they press ok they can proceed.
View 3 Replies
View Related
Apr 19, 2007
why the below code opens files as read only? What this code does is open all worksheets, in four different folders, whose filenames include the desired date. For example, if i want all worksheets for the 19th, then K117819, k127819, k217819 and K226119 all open. Except they open as read-only which requires saving to a different location and then renaming - which sort of defeats the time saving reason for running the code in the first place.
Public Sub Auto_Open()
Dim sCurFile As String
Dim sPath As String
Dim mpath As String
MsgBox "This tool will print all four production lines line report total sheet for any month and day in 2007"
mpath = InputBox("Enter the month i.e. 01 for January", "print")
fpath = InputBox("Enter day of the month to print (use leading 0's)?", "print")
Application. ScreenUpdating = False
Application.DisplayAlerts = False
Application.AskToUpdateLinks = False
'Get the path
sPath = "t:2007" & mpath & "k11"...............
View 3 Replies
View Related
Mar 31, 2014
When I had Excel 2010 and now with Excel 2013, whenever I open a workbook, it opens and displays to the row AFTER the last row of data. (So, if my last row of data is 38205, it will open starting at row 38206...hence I see no data until I hit Ctrl+Home). I have not found anything about this on the internet and I cannot find a setting. I need Excel to open to A1 so I don't freak out every time I open a workbook and see no data.
View 2 Replies
View Related
Apr 29, 2008
I'm new to VBA so my i'm having alot of problems figuring out simple stuff.
Below is my script and when i run it, the dates turns out incorrect.
I noticed this only happens to dates that are before 13th of each month.
Example,
1st May 2008 ( 01/05/2008)
will turn up as
5th Jan 2008 ( 05/01/2008)
However when i manually open the file Todays trades.csv
The date looks just fine.
Is there some problem with using VBA to call up the file?
View 9 Replies
View Related