I have a worksheet that is populated from userform information, and from a few other spreadsheets in the same file. I have used the following code:
Application.Dialogs(xlDialogPrint).Show
I ensure the sheet is activated before printing, and I have gotten the function working correctly.
This sheet and others in the workbook must be protected to prevent changes by the user outside of a userform. When I protect the sheet and add appropriate code to unlock that sheet a few things happen:
1. The userform is filled as designed.
2. The print dialog box shows up as designed.
3. When the print button is pressed on the dialog box, it will not print. Not a printer issue: It will not print to PDF either.
How can I get it to actually print the worksheet like I need?
You can unprotect the sheet by using
ActiveSheet.Unprotect
https://learn.microsoft.com/en-us/office/vba/api/excel.worksheet.unprotect
Then protect it after working with it using
ActiveSheet.Protect
https://learn.microsoft.com/en-us/office/vba/api/excel.worksheet.protect
banal code below must do the work without need to unprotect and protect
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Preview:=True, Collate:=True
Related
I have an excel document that is protected. I have a macro running to allow for expanding and collapsing rows in 1 of the sheets that looks like this:
Private Sub Workbook_Open()
With Worksheets("Part 1")
.EnableOutlining = True
.Protect UserInterfaceOnly:=True
End With
End Sub
This was working great, however now I would like to allow for "drawing" to have the text in that spreadsheet to be highlighted. I have gone into the "protect sheet" function to allow for "edit objects", I protect the sheet, save and exit. When I reopen the document it does not allow for me to use the "draw" function. And when I unprotect the sheet, the "edit objects" is selected, but the draw buttons do not work until I "unprotect" and then "protect" it again.
This is only happening in the sheet that has the macro running, thinking this might be a macro code. Any ideas?
As mentioned above, I have tried to unlock and relock the spreadsheet, however the edit objects function does not save upon next reopen. I am hoping to get assistance on the macro as I feel it is creating the error.
I use this code to hide the Excel sheet while I use the user form
Private Sub Workbook_Open()
Application.Visible = False
Calculator.Show
End Sub
But it hides all the Excel sheets I'm working on. Is there another code that enables me to hide only the user form sheet?
Your Application.Visible = False is referring to the entire Excel application, rather than a particular sheet or user form.
It's not entirely clear if you are trying to hide a sheet or a user form.
I think you are trying to hide a sheet and then show a user form.
If so, you can try this:
ThisWorkbook.Sheets("YourSheetName").Visible = xlSheetHidden
Calculator.Show
Note: you must hide the sheet before showing the userform (otherwise, the sheet will stay visible until the userform is closed).
I'm a new VBA user. I have a workbook with multiple worksheets. Each one has it own userform for data entry. The userform shows when I click on the sheet. After I'm done entering data, the worksheet is populated and the userform closes (unload). All this works well. However, after the initial data entry is complete, the goal is to use the data on the worksheets for other applications and the userform is no longer needed. What is the code or the terminology to say the userform should not reappear again when the worksheet is clicked on? Currently, I red X out of the userform. If I click the command button to close, it repopulates and I lose all my data.
Thanks!
As A.S.H commented; you could store the information in a number of ways. An easy example is declaring a variable outside of the Macro:
Public FormOpened as boolean
And then set FormOpened as true once the form has been shown. Then you could add a check to the start of the mouse-click macro:
If FormOpened = True then Exit sub
I have a question to ask about my userform. I hide my workbook and just userform will visible. It work perfectly in my computer because my computer is macro enabled. But in macro disabled computer, user still can edit my workbook before they enable the macro security warning.
Private Sub Workbook_Open()
Application. Visible=False
UserForm1.Show
End Sub
This is code I used to hide the workbook. Anyone could tell me how can I guide the workbook even in macro disable computer?
Thank
You could add a sheet telling the user to activate macros, protect it and hide all other sheets. You can also protect the workbook to prevent the user from adding or unhiding sheets. (The latter could also be done by setting them to very hidden).
If you need to show the sheets at some point for user interaction you can hide them again upon saving using the Workbook_BeforeSave event.
I have a template sheet that is copied through VBA into a new sheet.
The new sheet is added by clicking on a button that makes a userform pop up, and the information in the userform is transferred to the new sheet.
This new sheet contains locked headline cells as well as unlocked empty cells for the user to put information into. The sheet is protected but allows users to select locked and unlocked cells.
Everything worked for some months until the other day. When a new sheet is created and the user tries to fill in the unlocked cells, Excel responds as if they were locked!
The following information pops up:
"The cell or chart you're trying to change is on a protected sheet. To make changes, click Unprotect Sheet in the Review tab (you might need a password)."
This error disappears after the user does any of the following
1) double click in any empty cell (instead of just selecting it) and put in information this way and then click enter, then all cells behave normally.
2) activate any other worksheet and then return to this sheet
3) choose Format>Unprotect Sheet (this does not unprotect the sheet but it removes the error. If the user wants to unprotect the sheet then they have to click Format>Unprotect Sheet twice, i.e. first to remove this weird error and then to unprotect it).
I am trying, with VBA, to remove this error by doing any of 1, 2 or 3 above.
Any ideas how to solve this?
An additional problem is it is not possible to scroll with the mouse in the sheet while having the problem.
I tried the following code:
ActiveSheet.EnableOutlining = True
ActiveSheet.Protect Contents:=True, userInterfaceOnly:=True
After some googling I managed to solve this by doing the following:
Create a Module in VBA and add the following code:
Public Sub RefreshActiveCellSelection()
ActiveCell.Select
End Sub
Whenever you perform a Workbook.Activate or Worksheet.Activate, immediately call
Application.OnTime Now, "RefreshActiveCellSelection"
Another solution was to uninstall KB3085502
I found the answer here: http://answers.microsoft.com/en-us/office/forum/office_2013_release-office_install/microsoft-update-excel-2013-kb3085502-32-bit/0cc7d498-92cb-4478-9554-77cff286c847