I work with excel files that use a lot of "Notes".
I know I can right-click on a cell to toggle note visibility, and I also know the shortcut ALT+R+T+O. However these are cumbersome when I look to toggle notes constantly.
I've added a macro, on Ctrl+Q that reads:
Sub ToggleNote()
'
' ToggleNote Macro
'
' Keyboard Shortcut: Ctrl+Q
'
ActiveCell.Comment.Visible = Not ActiveCell.Comment.Visible
End Sub
But there are a few limitations with this:
I receive a new excel every day (by email) and It's cumbersome to convert it to .xlsm & add the macro.
Some of the tool we use in the company blocks .xlsm files making them hard to share.
The macro is a little glitchy if I accidentally use it on a cell with no comment.
Is there a good way to do this that I'm not aware of?
PS. The excel files are written using Python & XlsxWriter - it is feasible to modify the code that creates the excels.
There are two easy commands for this:
' Show all comments/notes
Application.DisplayCommentIndicator = xlCommentAndIndicator
' Hide all comments/notes (but show the indicator)
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
There also is:
' Hide all comments/notes, even the indicator:
Application.DisplayCommentIndicator = xlNoIndicator
But this makes it difficult to see which cells have comments/notes and which not.
You could use an Add In which would have the macro enable for each use of Excel. You can modify this to just happen with certain workbooks etc.
In the workbook_open of the Addin you could have
Private Sub Workbook_Open()
Application.OnKey "^q","mdlFunctions.DisplayNotes"
End Sub
Then in a module called mdlFunctions in the AddIn, have your toggling code, mine's DisplayNotes(). You may want to check for a comment being present within that code too.
You can just have this add in installed, then workboks won't become macro enabled, but you will have the macro function from the addin.
The excel files are written using Python & XlsxWriter - it is feasible to modify the code that creates the excels.
Yes. It is possible in XlsxWriter to generate the notes/comments as initially visible or hidden, either individually or for all comments in a worksheet. See
Related
Hi I have a question about clearing and pasting a selection from another workbook.
I am trying to make a macro that clears the old data I have in a tab and copies the data I have on my clipboard from another excel workbook in it's stead.
I kept getting an error before I noticed what was wrong. When the macro runs the clearing part, it cancels my selection/copy data I had, so the pasting part does not work. does anybody know how to circumvent it? I can't reference the excel where the data is coming from directly because it varies every time.
the code I use now for the clearing:
Sub clearData()
Worksheets("ZRFI08TW").Range("A5:M5000").ClearContents
End Sub
The coded i use now for the pasting of the data (i know its not the best, but trying different things before i noticed the conflict ended up with this one):
Sub copyData()
ActiveSheet.Range("A5").Select
SendKeys "^v"
End Sub
I can come up with two options, following the logic of your code for using SendKeys "^v" for a paste:
Using - Worksheets("ZRFI08TW").Range("A5:M5000") = ""
Assigning the Selection to a range and then selecting this range again and pasting it:
Dim myRange as Range
Set myRange = Selection
Worksheets("ZRFI08TW").Range("A5:M5000").ClearContents
myRange.Select
myRange.Copy
ActiveSheet.Range("A5").Select
SendKeys "^v"
But there should be a way better way to achieve what you are looking for. And as I am mentioning .Select, I feel an urge to mention this one - How to avoid using Select in Excel VBA.
I have finished a small Project at work and distributed the File to my coworkers.
I saved the file as .xlsm to enable makros. I have used the code for about 2 weeks now and never had any problems with it.
However when i sent them to my Coworkers one makro doesnt work.
I have multiple makros in the File and only one of them doesnt work anymore so i believe its the makros problem and not the new Excel version:
Sub Loomisinsert()
'Deletes old Data and inserts new
Sheets("MSE").Range("B2:J1000").Clear
Sheets("MSE").Range("B2:B2").Select
Sheets("MSE").Paste
'deletes unnecessary data
Sheets("MSE").Range("K3:N5000").Delete
Sheets("MSE").Range("P3:Q5000").Delete
Sheets("MSE").Range("S3:U5000").Delete
Sheets("MSE").Range("L3:L5000").Delete
End Sub
The user is only supposed to copy Data from another Workbook and use an excel button to insert the data at the right place and delete the correct cells.
As you can see i tried to specify which sheet to use for each command. And it works fine for me but not on my Coworkers Computer.
They have Excel 2013 and 2010 the same i use.
Below are some suggestions. Modify and try:
Option Explicit
Sub Loomisinsert()
With ThisWorkbook.Worksheets("Sheet1")
'Deletes old Data and inserts new
.Range("B2:J1000").Clear
.Range("B5").Copy .Range("B2") '<- Easy way to copy - paste
'Deletes unnecessary data
.Range("K3:N5000,P3:Q5000,S3:U5000").Clear'<- Does not need to use "L3:L5000" because included in "K3:N5000". Additionally, have in mind that *.Delete* may cause problem with columns & rows. It s more preferable to use *.Clear* or *.Clearcontents*. *.Clear* used to clear both formats and value. In the other hand *.Cleatcontents* just empty the cell from value.
End With
End Sub
A friend of mine works at Verizon and asked me If excel has built in functions for whenever he types "open" into a cell it will return "8:30-5:00" into that cell.
I hounded google for an hour. I cant seem to find what I am looking for.
Thank you.
You can use Custom functions in Excel. Custom functions, like macros, use the Visual Basic for Applications (VBA) programming language.
https://support.office.com/en-us/article/Create-Custom-Functions-in-Excel-2007-2f06c10b-3622-40d6-a1b2-b6748ae8231f
You need a Worksheet Event Macro. This is a small routine that will constaintly monitor cells on a worksheet and take action if data is typed into them.
Say we want to monitor cell B9. Include the following in the worksheet code area:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim B9 As Range
Set B9 = Range("B9")
If Intersect(Target, B9) Is Nothing Then Exit Sub
If B9.Value <> "Open" Then Exit Sub
Application.EnableEvents = False
B9.Value = "8:30-5:00"
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macro:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
A non-VBA solution is possible using Excel's built-in Autocorrect facility.
On the File tab in Excel 2013 click Options -> Proofing -> Autocorrect and enter "open" in the Replace: box and "8:30-5:00" in the With: box (without the quotes).
This is not case sensitive so will work for both "open" and "Open".
If you are ever likely to want "open" or "Open" to appear in a string you could add an escape character such as backslash to your replace string "\open".
I currently have this VBA -
Sub StartTimer()
Application.OnTime Now + TimeValue("00:00:15"), "AutoCalc"
End Sub
Sub AutoCalc()
Application.CalculateFull
Sheets("Kine").Range("B603:E603").Copy _
Destination:=Workbooks("AutoImportAverages.xlsx").Worksheets("AvgKine").Range("B1:E1")
Application.OnTime Now + TimeValue("00:00:15"), "AutoCalc"
End Sub
The .OnTime command is working perfectly without the Copy/Paste section, which is great.
This gives me a list of values from an SQL query that will auto-update, as well as an average at the bottom of each column of values.
I'm trying to set this up so that the average will automatically be added onto columns in Minitab but I believe that the Macro is stopping the Auto-Update in Minitab.
So my idea is to copy-paste the averages into an Excel Workbook that has no macros of its own and then link that to Minitab.
Have I put in the Copy-Paste code wrong or is there some issue with where the macros need to be stored and how?
Quick Edit - I should add that current code gives "Run-Time Error 9, Subscript out of range" and highlights copy/paste code.
I've found the solution.
My destination workbook was open in a separate window so the source wasn't recognising it as being open. Bit of a nightmare!
It's necessary to have both workbooks open in the same instance of Excel.
Additionally, my original paste code only pasted "#REF". I have changed that to -
Workbooks("AutoImportAverages.xlsx").Worksheets("AvgKine").Range("B1:E1").PasteSpecial xlValues
Works much better.
One more thing, in case anybody might find it useful. The source workbook must be active in order to carry out the auto-update.
Adding below line sorted out most issues though its still a work in progress -
ThisWorkbook.Activate
I want to create an excel template that will includes formulas for dating the columns. However, since those formulas will be based on TODAY(), I need to convert them to static strings (so the dates don't change everytime someone opens it). Is there a way to add a macro that will run automatically when someone creates a new spreadsheet based on the template? (Similarly to Auto_Open(), only on Create, rather than Open). If so, I could just create a macro that will replace the formulas with their results upon document creation. Can this be done?
[Note: I'm not married to this solution; it just seemed like the simplest way to protect my spreadsheet. If someone can suggest an alternative approach, I'd be obliged.]
I have a couple thoughts...
If you run a copy/paste values macro every time it really won't matter, right?
You could check if the file exists yet (has been saved), and if not
then this must be the template opened as a new workbook, maybe?
Code:
Private Sub Workbook_Open()
If Dir(ActiveWorkbook.Name) = "" Then
'run the macro?
MsgBox "I'm gonna run this macro"
End If
End Sub
You could have a cell on one of the sheets, that will never be used,
or is hidden, that will store whether or not to run the macro, and
change that when the file is opened or when the macro is ran. Then
have a macro run on open that checks that cell. (Or custom/document property)
You could populate the cells that have the today() formula only on
open and if they are already populated then don't run the macro?
I realized that there is no need for a Workbook_Create() function, as that behavior can be emulated by simply deleting the macro after it has run once (which happens when it is first created). Deleting macros is done automatically when the file is saved with a .xlsx extension. In addition, you need to prevent the macro from running when you open the template itself (while editing the it). You can hold the SHIFT key when opening it to prevent auto-run macros, but since that method isn't foolproof, I added this code at the top:
Private Sub Workbook_Open()
'If we're opening the template, don't run the macro
If Application.ActiveWorkbook.FileFormat = xlOpenXMLTemplateMacroEnabled Then
Exit Sub
End If
...
'add code here to SaveAs .xlsx, thus removing the macros, so it won't run every time.
End Sub
(Note: I didn't show my SaveAs code as it is rather messy: I wanted to suppress the default warning about losing macros, but wanted to also protect the user from inadvertantly overwriting previous file. If anyone is interested, I could post it)