Process name: wdout
Purpose: Use the defined template to automatically shape the template {????} And {photo} is replaced with the photo. If there is no photo, the replacement character is deleted.
Parameter: photofile -- the path string of the photo file, which is the complete absolute path. It does not determine whether the file exists. If the file does not exist, an error will occur.
Insert an image with only one sentence
Wdapp. selection. inlineshapes. addpicture filename: = _
Photofile, linktofile: = false, savewithdocument: = _
True
You can use the word macro to get the corresponding code.
Private function wdout (byval photofile as string)
''{Unit} {fee name} {capital amount} {appraisal unit} {operator} {date}
Dim wdapp as object, wddoc as object
Dim I as integer
If checkword = false then
Msgbox "No wordsoftware or software installation error! ", Vbexclamation
Exit Function
End if
If dotname = "" or not fileexist (dotname) then
Msgbox "the print template is not found and cannot be printed !! ", Vbexclamation
Exit Function
End if
Msgwinshow "Generating document from template ..."
''If not wddoc is nothing then
''On error resume next
''Wddoc. Close wddonotsavechanges
''Set wddoc = nothing
''Wdapp. Quit
''Set wdapp = nothing
''On error goto 0
''End if
''
Set wdapp = Createobject ("word. application ")
With wdapp
'. Visible = true
Set wddoc =. Documents. Add (dotname, false, 0, true) ''wdnewblankdocument = 0
End
For I = 0 to adors. Fields. Count-1
'With. content. Find
Select case adors. Fields (I). Name
Case "photo"
Wdapp. selection. Find. clearformatting
With wdapp. selection. Find
. Text = "{photo }"
. Replacement. Text = ""
. Forward = true
. Wrap = wdfindcontinue
. Format = false
. Matchcase = false
. Matchwholeword = false
. Matchbyte = true
. Matchwildcards = false
. Matchsoundslike = false
. Matchallwordforms = false
End
Wdapp. selection. Find. Execute
Wdapp. selection. Delete unit: = 1, Count: = 1' delete 1 = wdcharacter
If photofile> "" then
Wdapp. selection. inlineshapes. addpicture filename: = _
Photofile, linktofile: = false, savewithdocument: = _
True
Wdapp. selection. moveleft unit: = wdcharacter, Count: = 1
Wdapp. selection. moveright unit: = wdcharacter, Count: = 1, extend: = wdextend
Wdapp. selection. inlineshapes (1). Fill. Visible = 0 ''0 = msofalse
Wdapp. selection. inlineshapes (1). lockaspectratio =-1 ''-1 = msotrue
Wdapp. selection. inlineshapes (1). Height = 28*4.1
Wdapp. selection. inlineshapes (1). width = 28*2.8
End if
Case else
With wdapp. selection. Find
. Clearformatting
. Replacement. clearformatting
. Text = "{" & adors. Fields (I). Name &"}"
. Replacement. Text = adors. Fields (I). Value &""
. Forward = true
. Wrap = 1' 1 = wdfindcontinue
. Format = false
. Matchcase = false
. Matchwholeword = false
. Matchbyte = true
. Matchwildcards = false
. Matchsoundslike = false
. Matchallwordforms = false
. Execute Replace: = 2' 2 = wdreplaceall
End
End select
Next
Wdapp. Visible = true
Set wddoc = nothing
Set wdapp = nothing
Msgwinhide
End Function