Result = Result & ConvertDigit(Mid(sngNumber, 3)) 'if not, then convert the ones place digit Result = Result & ConvertTens(sngNumber, Mid(sngNumber, 2)) Result = ConvertDigit(Left(sngNumber, 1)) & "hundred " 'do we have hundreds place digit to convert? Private Function ConvertHundreds(ByVal sngNumber) If strDollars = "" And strCents = "" Then SngNumber = Left(sngNumber, Len(sngNumber) - 3) If strTemp "" Then strDollars = strTemp & Place(lngCount) & strDollars StrTemp = ConvertHundreds(Right(sngNumber, 3)) SngNumber = Trim(Left(sngNumber, lngDecimal - 1)) StrCents = ConvertTens(sngNumber, strTemp) StrTemp = Left(Mid(sngNumber, lngDecimal + 1) & "00", 2) If IsNumeric(sngNumber) And Val(sngNumber) 0 Then “Error Description: ” & Err.SngNumber = ActiveDocument.FormFields("NumberAmount").Result “Error Number: ” & Err.Number & vbCrLf & _ MsgBox “The following error has occured.” & vbCrLf & vbCrLf & _ MsgBox “The specified file ‘” & sDocName & “‘ could not be found.”, _ ODoc.SaveAs FileName:=(ThisWorkbook.Path & “/offerte/” & oDoc.FormFields(“Numero_Offerta”).Result & “_” & oDoc.FormFields(“Name”).Result & “.docx”) ‘oDoc.FormFields(“CheckboxName”).CheckBox.Value = True ‘Checkbox ODoc.FormFields(“Name”).Result = ThisWorkbook.Sheets(“Offerte”).Range(“B” & LastRow).Value ‘Textbox ODoc.FormFields(“Numero_Offerta”).Result = ThisWorkbook.Sheets(“Offerte”).Range(“A” & LastRow).Value ‘Textbox LastRow = ThisWorkbook.Sheets(“Offerte”).Cells.SpecialCells(xlCellTypeLastCell).Row SDocName = (ThisWorkbook.Path & “/modello_offerta.dotx”) Set oApp = CreateObject(“Word.Application”) If Err.Number 0 Then ‘Word isn’t running so start it Set oApp = GetObject(, “Word.Application”) ‘See if word is already running ‘Requires a reference to the Word object library I’ve figured that word file is opened every two times, not alwaysĬlick again on the macro button –> open word, open file, filling text, save file renamed, everything ok
#Vba spell number without form fields in word code
I’ve adjusted the code for my purpose, I have to retrieve the last row of an excel and fill the template word, then save with another name. ODoc.FormFields("CheckboxName").CheckBox.Value = True 'Checkbox Error_Handler_Exit:Įnd Sub Form Field MS Access VBA Programming MS Excel VBA Word 7 responses on “ VBA – Word – Update/Fill-in Document Form Fields”
ODoc.FormFields("TextboxName").Result = "NewValue" 'Textbox SDocName = "YourWordDocToOpenFullPathAndExtension" Set oApp = CreateObject("Word.Application") If Err.Number 0 Then 'Word isn't running so start it Set oApp = GetObject(, "Word.Application") 'See if word is already running 'Requires a reference to the Word object libraryĭim sDocName As String On Error Resume Next It may not be sold/resold or reposted on other sites (links ' copyright notice is left unchanged (including Author, Website and
' Copyright : The following may be altered and reused as you wish so long as the ' Purpose : Update/Fill-in a Word document's form fields VbCritical, "An Error has Occurred!" End If Resume Error_Handler_Exit "Error Description: " & Err.Description, _ "Error Number: " & Err.Number & vbCrLf & _ MsgBox "The following error has occurred." & vbCrLf & vbCrLf & _ MsgBox "The specified file '" & sDocName & "' could not be found.", _ Set oDoc = Nothing Set oApp = Nothing Exit Sub ODoc.FormFields( "CheckboxName").CheckBox.Value = True 'Checkbox ODoc.FormFields( "TextboxName").Result = "NewValue" 'Textbox
SDocName = "YourWordDocToOpenFullPathAndExtension" Set oDoc = oApp.Documents.
'Requires a reference to the Word object library Dim oApp As Object 'Word.Application Dim oDoc As Object 'Word.Document Dim sDocName As String On Error Resume Next Set oApp = GetObject(, "Word.Application") 'See if word is already running If Err.Number 0 Then 'Word isn't running so start it Set oApp = CreateObject( "Word.Application") It may not be sold/resold or reposted on other sites (links ' back to this site are allowed). ' Website : ' Purpose : Update/Fill-in a Word document's form fields ' Copyright : The following may be altered and reused as you wish so long as the ' copyright notice is left unchanged (including Author, Website and ' Copyright). '- ' Procedure : UpdateDoc ' Author : CARDA Consultants Inc.