espenskeie
Well-known Member
- Joined
- Mar 30, 2009
- Messages
- 636
- Office Version
- 2016
- Platform
- Windows
Hello
Does anyone know how I can solve the issue where I have a userform with a txtbox where I can write optional information regarding a customer.
When I hit OK-button this text is put in a cell in Excel.
Later I run another code that pull this text and some other simple words into a replacement macro that opens a .docx file and replace the words one by one.
But when I come to this optional text, which can be 30 words or more, pluss lineshift etc. I get error message that the ...."string is too long"
I have read about the 255 word-limit, but I cannot see that I'm even close to that one?
This is not the Userform Code, but it is this code that produces the Error-message.
Regards
Espen
Does anyone know how I can solve the issue where I have a userform with a txtbox where I can write optional information regarding a customer.
When I hit OK-button this text is put in a cell in Excel.
Later I run another code that pull this text and some other simple words into a replacement macro that opens a .docx file and replace the words one by one.
But when I come to this optional text, which can be 30 words or more, pluss lineshift etc. I get error message that the ...."string is too long"
I have read about the 255 word-limit, but I cannot see that I'm even close to that one?
Code:
Option Explicit
'the document
Dim Inv_doc As Object
'the application
Dim WD As Object
Dim FName As String
Dim DesktopB As String
Option Base 1
Sub AutoNameEdit()
Const wdReplaceAll = 2
Dim objSelection
Dim WDarray As Variant
Dim WDcnt As Long, myCnt As Long, i As Long
i = 1
WDarray = Array("txtCompName", "txtCompNo", "txtCompRef", "txtRefTitle", _
"txtCompName", "txtStorage", "txtSpecial", "txtCompRef", "txtSafeRef", "txtStreet", "txtStreetNo", "txtPostNo", "txtCity")
FName = ActiveWorkbook.Sheets("Ark3").RAnge("B1").Value
DesktopB = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
Dim which_document As String
which_document = DesktopB & "\SalesTools\Intro.docx"
'need an instance of word
Set WD = CreateObject("Word.Application") 'Set objWord = CreateObject("Word.Application")
WD.Visible = True
Set Inv_doc = WD.Documents.Open(which_document) 'Set objDoc = objWord.Documents.Open("C:\Scripts\Test.doc")
Set objSelection = WD.Selection
For myCnt = 1 To UBound(WDarray)
objSelection.Find.Text = WDarray(myCnt)
objSelection.Find.Forward = True
objSelection.Find.MatchWholeWord = True
If objSelection.Find.Execute Then
objSelection.Find.Replacement.Text = Sheets("Ark3").Cells(i, 2).Text
objSelection.Find.Execute , , , , , , , , , , wdReplaceAll
End If
i = i + 1
Next
WD.Activate
Inv_doc.SaveAs DesktopB & "\SalesTools\" & FName & " - " & Date & ".docx"
Inv_doc.Close
WD.Quit
Set Inv_doc = Nothing
Set WD = Nothing
End Sub
This is not the Userform Code, but it is this code that produces the Error-message.
Regards
Espen