Save user form input value for next time edit - userform

Will the solution provided in the solution Save userform value for next time work for word documents as well?

Related

How to use a macro to "tab" between form fields, in a table, in a protected Word document?

I'm writing a macro which copies data from an excel spreadsheet to a word document (to save myself time copy/pasting). The word document is protected and has legacy form fields to enter data. I'm trying to figure out how to iterate between these fields. For most of the fields, Selection.Next(Unit:=wdParagraph, Count:=1).Select works just fine. However, some of the fields are in a table, which that solution doesn't work for.
Selection.Next(Unit:=wdParagraph, Count:=1).Select will get me into the form in the first cell of the table. But it stops there, failing to go to the next field. I've tried a number of variations, such as increasing the Count, and for Unit tried wdParagraph, wdItem, wdCell, wdColumn, wdTable, wdSection, and wdCharacter. No matter what I try, the selection stays in the first cell of the table.
I've also tried Selection.TypeText, Selection.NextField.Select and Selection.MoveDown (and similar), which throw 4605 errors that I assume are due to document protection.
Found the solution:
<document variable here>.FormFields(<index of form field in table>).Select

Use a Userform for MS Word to Input to Values in Form Fields

I am trying to automate a repetitive manual task for another department. They have a word template several pages long. They have to enter data several times each time they use it. Many of these are repetitive "fields". I thought about setting up custom form fields. But having them go through the navigation and know the field names to update them is not optimal. I found one solution to create a bookmark for each data input, and create links to that bookmark where it needs to be repeated - better but not optimal. I was hoping to create a userform where they can enter all the data and have it populate bookmarks, custom fields, to whatever.
I found a video that does this, but when I try the code, it does not update the bookmark. i created userform with Textbox1, and a CommandButton, and a bookmark in the document called MWDate. The code I am trying to get to work is:
Private Sub CommandButton1_Click()
Dim MWDate As Range
Set MWDate = ActiveDocument.Bookmarks("MWDate").Range
MWDate.Text = Me.TextBox1.Value
Me.Repaint
UserForm1.Hide
End Sub
This is a code example I grabbed and modified from the tutorial video. I don't know what the "Me." is. It does not populate the bookmark, which tells me it is not getting to the repaint line. Nor does it ever get to the hide line.
Anyone have a fix? Or a better way? Thanks for any help you can give.

Saving cell Presets in a dropdown list

At the moment I have created a spreadsheet which takes a bunch of inputs, runs them through a list of formulas, and then spits out the results onto a "report" worksheet.
I've been manually saving each of these reports as separate CSVs but I was hoping for a better method moving forward as it is getting quite tiring to have to open 10 CSVs when i do my monthly reports.
I am looking for a way to start saving all of these reports into a "database". My hope to to have one cell be for an user entry name and for two buttons. One to save the current report under the name entered by the user, and two to remove old records. I would then be able to revisit old entries by selecting them in the dropdown.
I've dabbled with VBA and Macros in the past but this is a little more complicated than what I've dealt with in the past. Looking for some help/direction.
Thanks for your time!
Depending on how your reports need to be used, you might find it satisfactory to simply make your data into one big Excel Table ( Insert Tab > Table ). When you do this, Excel will automatically fill-down any formulas that you enter in a column, and also show the formula using the headers instead of A1-style references.
I use this format, adding Y under Remove from Active List on each line that is already done. Then whenever I save the file or look at it for today's status, I filter out what's old and just look at the new. The other filters enable copy-pasting or printing whatever arrangement I like.
The filters and other things in the table can be referenced in VBA as Sheets("ThisSheet").ListObjects(1), which is an object with a number of useful properties and methods.
For VBA information, read more here: https://www.thespreadsheetguru.com/blog/2014/6/20/the-vba-guide-to-listobject-excel-tables
This is my code for auto-filtering the table to hide inactive items at time of save. You add it at ThisWorkbook in the VBA editor:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Sheets("Sheet1").Activate
SelectedCell = ActiveCell.Address 'this saves your screen selection for after the filtering
ActiveSheet.ListObjects(1).Range(1, 1).Select
If ActiveSheet.ListObjects(1).AutoFilter.FilterMode = True Then
ActiveSheet.ListObjects.Item(1).AutoFilter.ShowAllData
End If
A = ActiveSheet.ListObjects(1).Range.Rows(1).Find("Remove from List").Column - _
ActiveSheet.ListObjects(1).Range.Column + 1
ActiveSheet.ListObjects(1).Range.AutoFilter field:=A, Criteria1:="="
Range(SelectedCell).Select
End sub

Excel: How to open the Data Entry form from VBA?

There is a built-in data entry form in Excel. I have added a shortcut to this and its quite good. It has a few little issues (i.e. it depends what cell you have selected as to what data it fills in the form).
So I want to wrap it up into a macro and add my own button. My little macro will select the appropriate cell. So the question is, using VBA, how do you call the build-in Data Entry form?
-EDIT-
Seems my question is not clear... so here is some more:
There is a built-in data entry form that you can use, see here: Built-in Data Entry Form
I want to open this form using excel VBA, like this:
Sub OpenTheBuiltinDataEntryForm()
' Add code here to open the built-in data entry form...
End Sub
The line you are looking for is:
Activesheet.ShowDataForm
but note that your data table must begin within A1:B2 or be named Database or you will get an error.

Show Cell Range on UserForm; then update

I've been using a crude method to help the user update some cells - by having them in a sheet. Is there any way I can display the various ranges in a userform, one by one, then have the user update them, click a button and move onto the next one?
Essentially, can I have Excel automatically generate an input form based on a range? The process of updating and saving back to the sheet I can do; it's the production of the correct form that I can't.
It's possible to do this, but the only way I can think of is to make a userform that automatically populates itself based on a range passed in. This way you could have different macros in Excel that call the form to populate based on different ranges. I built a proof of concept Excel file for trying this, and it seems to work, the only issue I can think of being that you need to figure out a way to tell the user what input field is what.
I think what needs to be done is to add controls programmatically to a userform (I name the textboxes as the cell address it's going to populate) then when the form is closed loop through all the textboxes and populate the cells with the textbox values.
You can see what I did at:
https://my.syncplicity.com/share/uicgbs3rl0/InputForm.xls
I think all that would need to be done is for you to work out how to add labels for the textboxes, and make sure the form is resized based on the controls you add...
I am not quite shure what you are looking for, but you could insert a second sheet and use it as a "form". An other way could be a dialog box with an input field.
Either way, you present the cells you want the user to change one by one, using a vba-function. You implement a "previous field" and a "next field" button, so the user can step through the range of cells. If the user hits "next field", you save his input and take the next cell from a previous defined range of cells.
You could have a "config field" in which you define the range of cells you want to change.
This is pretty rough and old-fashioned but if you have the data in standard list format - i.e. column headers in the first row of your range and then one record of data in each row below - then selecting a cell within the range and going Data > Form will give you a crude input form with roughly the functionality you need.
You can also do this in VBA by calling the ShowDataForm method of the appropriate worksheet. Just select a cell within whichever range you need first. The macro will remain paused until the user closes the data form