PDA

View Full Version : [SOLVED:] Save Button for Word Doc + User Form in relation with Sharepoint content type docs



IzissX
05-09-2016, 05:42 AM
Hello everybody,

I have some issues with VBA in Word (which doesn't work as it works in Excel), but here is what i am trying to do.

I have a word document saved as a template/content type in a template library in Sharepoint, which when i go to the Document library where my normal files should be saved, i just open from there as a new document based on this template. This is the part that works.
16131

When i open this document i have created a button to do the following:

Open a user form that requires some inputs to fill in some built in document properties and other properties that come from Sharepoint columns
After this user form is filled in and the document properties are already changed, the file then to be saved according to one of the document properties (Example "Root Cause - [KI ID]" where "KI ID" is one of the doc properties to be filled in with the user form) to a place of my choosing

For the greater part it does what it should, but more than that. Somehow, after it saves my document, it asks me to save the template as well, which in the case of other excel files (created with the same logic in mind) doesn't happen. And this is the part where i am completely baffled by why or how this is happening. It shouldn't ask me to save the template because it is a template and has to stay as it is. Please tell if there is something i am doing wrong or if there is an easier way to do it. Or anything that can make this work. And thank you in advance.

Bellow you have my code for this procedure and for the user form (so you can understand what comes from where.

16132
User Form internal code


Private Sub CommandButton1_Click()
Unload Me
End Sub

Private Sub Save_But_Click()

If Me.ITDID_txt.Value = "" Then
MsgBox "Please insert Known Issue ID"
End If

If Me.ITDTitle_txt.Value = "" Then
MsgBox "Please insert Known Issue Title"
End If

ThisDocument.ContentTypeProperties("Known Issue ID") = Me.ITDID_txt
ThisDocument.BuiltInDocumentProperties("Title") = Me.ITDTitle_txt
ThisDocument.ContentTypeProperties("OAL reference ID") = Me.OALID_txt
Unload Me


End Sub

Save Button code


Private Sub CommandButton1_Click()

Word.Application.DisplayAlerts = wdAlertsNone
On Error GoTo End_Part
save_form.Show
save_form.ITDID_txt.SetFocus

strFilePath = "https://workspace.wx-t.energy.com/sites/Playground/ras/MB/Doc test 1/"
strFileName = "Root Cause - " & ThisDocument.ContentTypeProperties("Known Issue ID").Value & ".docm"

With Dialogs(wdDialogFileSaveAs)
.Name = strFilePath & strFileName
.Show
ActiveDocument.SaveAs2 FileName:=.Name, Fileformat:=wdFormatXMLDocumentMacroEnabled
End With



End_Part:
Word.Application.DisplayAlerts = wdAlertsAll
End Sub

gmayor
05-09-2016, 09:10 PM
You are using 'ThisDocument' to write to values in the document. ThisDocument is the document that contains the macro, which presumably is the template and so it is changed, hence the prompt to save the template. You need to change ThisDocument to ActiveDocument to save the values in the document.

IzissX
05-11-2016, 12:46 AM
Thank you so much Gmayor! It works as it should now. Thank you for that!