I have written a simple macro to force end users to view an EULA and then click a command button to accept the terms. On clicking the tabs for the workbook open allowing the user to work through the book. This works fine in Excel 2010 and all previous version but not in Excel 2013.
I get this error:
This is the code:
Sub OpenSheets()
'
' OpenSheets Macro
'
'
Sheets("EULA").Select
Sheets("Infection_Worksheet").Visible = True
Sheets("Infection_Worksheet").Select
Sheets("Exit_Site_Infection_Chart").Visible = True
Sheets("Exit_Site_Infection_Chart").Select
Sheets("Peritonitis_Chart").Visible = True
Sheets("Exit_Site_Infection_Chart").Select
Sheets("%_Pts_peritonitis_free").Visible = True
Sheets("%_Pts_peritonitis_free").Select
Sheets("Pt_numbers").Visible = True
Sheets("Pt_numbers").Select
Sheets("Results").Visible = True
Sheets("Results").Select
Sheets("Instructions").Visible = True
End Sub
Does anyone have any suggestions?
Underscores represent continuation to the next line in VBA.
Try this Sheets("Infection" & Chr(97) & "Worksheet").Visible = True
etc etc etc
Related
I have 3 checkboxes. When a user opened my sheet, he/she must not check checkboxes. I want them to be disabled. How can I do that?
Not sure if you meant ActiveX or FormControl, so here you go
Code
Private Sub Worksheet_Activate()
Dim myActiveX As Object
Set myActiveX = Sheet1.OLEObjects("CheckBox1")
myActiveX.Object.Value = True
myActiveX.Object.Locked = False ' Make it False if you wish to enable it
myActiveX.Object.Enabled = False ' Another option to disable
Dim myFormControl As CheckBox
Set myFormControl = ActiveSheet.Shapes("Check Box 1").OLEFormat.Object
myFormControl.Value = True
myFormControl.Enabled = False ' Make it True if you wish to enable it
End Sub
Live GIF demo
You have to write some VBA code in order to do that.
Let's suppose that you have 3 CheckBoxes in your first sheet.
By holding the "Alt" key on your keyboard and the pressing one time the "F11" key, opens Microsoft Visual Basic. ( Alt + F11 )
At your left hand you can see the "VBAProject" tree.
Double click on the "ThisWorkbook" file and copy the following code in the window it will appear:
Private Sub Workbook_Open()
void = uncheckAllCheckboxes()
End Sub
Function uncheckAllCheckboxes()
ThisWorkbook.Worksheets(1).CheckBox1.Value = False
ThisWorkbook.Worksheets(1).CheckBox2.Value = False
ThisWorkbook.Worksheets(1).CheckBox3.Value = False
End Function
Save the excel file as "Excel 97-2003 Workbook" type (.xls)
Close your excel.
Open the file you have previously saved and everything will work fine.
;)
P.S.: It is important to enable macros from your excel settings
I'm getting a frustrating error in my macro code. I have a small bit of code in two subs one opens all data groups and changes some of the print options and the other closes the groups and changes some of the print options.
This works fine but when I save and close on re-open if I click the macro buttons I get a 400 error message. To fix this I have comment out all the .pagesetup code and then run the macros again then uncomment and run the macro line by line and then the 400 error will disappear. However once I save and close this will come back and I have to repeat everything. Any help would be greatly appreciated.
Sub PropertyStrat_Click()
'
' PropertyStrat_Click Macro
'
ActiveSheet.Outline.ShowLevels RowLevels:=2 ' to expand the rows
Worksheets("Sheet1").PageSetup.Orientation = xlPortrait
Worksheets("Sheet1").PageSetup.PaperSize = xlPaperA3
Worksheets("Sheet1").PageSetup.Zoom = False
Worksheets("Sheet1").PageSetup.FitToPagesTall = 1
Worksheets("Sheet1").PageSetup.FitToPagesWide = 1
Worksheets("Sheet1").PageSetup.CenterHorizontally = True
Worksheets("Sheet1").PageSetup.CenterVertically = True
End Sub
Sub SimpleView_Click()
ActiveSheet.Outline.ShowLevels RowLevels:=1 ' to collapse the rows
Worksheets("Sheet1").PageSetup.PrintArea = "$A$1:$J$29,$A$30:$J$50"
Worksheets("Sheet1").PageSetup.Orientation = xlLandscape
Worksheets("Sheet1").PageSetup.PaperSize = xlPaperA4
Worksheets("Sheet1").PageSetup.Zoom = 100
Worksheets("Sheet1").PageSetup.CenterHorizontally = False
Worksheets("Sheet1").PageSetup.CenterVertically = False
End Sub
I have an addin with an UDF getRegExResult. I want to add a function description and arguments descriptions to this function, so when user installs the addin, closes, opens excel few times and goes to "Insert Function" Dialog box he will be able to find the function with description of the arguments.
The same is asked here. I found one answer that suits my needs. Except...
I want to be able to do this through an Excel Addin. My idea is to put call into addin workbook_open event like so:
Private Sub Workbook_Open()
Call getRegExResultRegister
End Sub
Public Sub getRegExResultRegister()
Application.MacroOptions Macro:="getRegExResult", Description:="Returns a concatenated string of NONE, ONE, or ALL Regular Expression Match(es).", Category:="User Defined", _
ArgumentDescriptions:=Array("Source string to inspect for matches.", _
"Regular Expression Pattern. E.g. ""\d+"" matches at least 1 or more digits.", _
"[Default = True] True = Returns all the matches found. False = Returns only the first match.", _
"[Default = True] True = Not case sensitive search. False = Case sensitive search.", _
"[Default = "";""] Delimiter to insert between every macth, if more than 1 matches are found.")
End Sub
After I install the addin, close, open excel, I get runtime error 1004: "Cannot edit a macro on a hidden workbook. Uhnide the workbook..."
Question 1
How to unhide an addin workbook? I tried to put Thisworkbook.Windows(1).visible = True into the Workbook_open event before the call to register, but that results in Runtime 9, subscript out of range.
Question 2
If the unhide addin is impossible, is there any other way to do this?
Thanks for help.
Similar questions:
Excel Register UDF in Personal.xslb
Edit #1
Current code does what I want, with one bug. When I open some existing workbook, I get 2 excel windows. One of the opened workbook (correct), one of the addin (not wanted). How to get rid of the second window?
Private Sub Workbook_Open()
With ThisWorkbook
.IsAddin = False
Call getRegExResultRegister
.IsAddin = True
.Saved = True
End With
End Sub
Use the following code before setting the .MacroOption:
Application.AddIns("Your Addin name").Installed = True
This code may need to be preceded by :
Application.AddIns("Your Addin name").Installed = False
According to MSDN Blog, it is because automation loaded AddIns are not really opened at startup. So you have to close it before re-openning it.
Note that "Your Addin name" is not the filename of the AddIn but its Name as it appears in the Add-ins option windows.
Edit: Full code, don't forget to edit the AddIn name
Public Sub getRegExResultRegister()
Application.AddIns("Your Addin name").Installed = False
Application.AddIns("Your Addin name").Installed = True
Application.MacroOptions Macro:="getRegExResult", Description:="Returns a concatenated string of NONE, ONE, or ALL Regular Expression Match(es).", Category:="User Defined", _
ArgumentDescriptions:=Array("Source string to inspect for matches.", _
"Regular Expression Pattern. E.g. ""\d+"" matches at least 1 or more digits.", _
"[Default = True] True = Returns all the matches found. False = Returns only the first match.", _
"[Default = True] True = Not case sensitive search. False = Case sensitive search.", _
"[Default = "";""] Delimiter to insert between every macth, if more than 1 matches are found.")
End Sub
It seems like this guy has had the same problem as me, but the vbModeless doesn't seem to do the trick.
I'm creating a simple add-in, and I want VBA to open a word file, copy the entire content and paste it in the original document.
It works perfectly when executed from the VBA editor or even after the first run where it debugs, but opening a Word instance for the first time and trying to execute the code from the add-in seems to be a problem.
The code is as follows:
Sub insertFigureFrame(control As IRibbonControl)
StandardFrames.StartUpPosition = 0
StandardFrames.Top = Application.Top + (Application.Height - StandardFrames.Height) * 0.5
StandardFrames.Left = Application.Left + (Application.Width - StandardFrames.Width) * 0.5
StandardFrames.Show
End Sub
Sub Standard()
Dim OriginalDocument As String
Dim SaveChanges As Boolean
Dim doc As Document
On Error GoTo err:
Application.DisplayAlerts = wdAlertsNone
Application.ScreenUpdating = False
OriginalDocument = ActiveDocument.Path
Documents.Open MyTemplate
Selection.WholeStory
Selection.Copy
Documents("MyTemplate").Close (SaveChanges = False)
Documents.Open (OriginalDocument)
Selection.PasteAndFormat wdPasteDefault
Exit Sub
err:
Call errHandling
End Sub
The StandardFrames Userform calls the sub Standard.
Any idea what might cause the problem?
EDIT:
I'm using Word 2007 and Windows XP.
Try hidding your userform before you open a document:
Sub Standard()
StandardFrames.Hide
'The rest of your code
End Sub
I have an excel dashboard which works such that before the excel file is closed, I would like to display all the EXCEL ribbon, so that next time excel is opened, the application / excel will show the ribbon. At present, it does not show the ribbon if excel is opened.
Private Sub Workbook_BeforeClose(cancel As Boolean)
On Error Resume Next
Application.ScreenUpdating = True
ActiveWindow.DisplayWorkbookTabs = True
Application.DisplayFormulaBar = True
Application.DisplayFullScreen = False
Application.DisplayStatusBar = True
Application.DisplayScrollBars = True
Application.ScreenUpdating = True
Sheets("Introduction").Select
End Sub
This is an .xls file with Macro and supposed to work in Excel 2003 and Excel 2007.
Also, if "Cancel" is clicked, I do not want to show any of the above / ribbon, as user is supposed to get a protected view of the excel dashboard.
If the ribbon is closed by default, you can open it again by double clicking on one of the tabs (for instance, the Home tab).
(See this for more details).
If, however, you wish to write an event to take place when the workbook opens, then use the Workbook_Open() event from the ThisWorkbook Excel Object.
try this Application.ExecuteExcel4Macro " show.toolbar(""Ribbon"",true)"
to hide
Application.ExecuteExcel4Macro " show.toolbar(""Ribbon"",false)"