Posts: 125
Threads: 20
Joined: Jan 2021
01-18-2021, 08:05 AM
(This post was last modified: 01-18-2021, 08:09 AM by macman.)
hello everyone,
I want to save the QM code as a word file
The following code, can achieve this goal,
Operation steps:
1. Open the QM code[Eg, test] to be saved, press Ctrl + A to select all, and then press the right mouse button to select Other Formats-->Copy HTML--->With Tabs and Spaces
2. run Macro9 , The created word file will be opened automatically
but there are a few places, not very convenient
1.
How to automate the first step above? Call a function to implement it?
2.
In word file, I need to delete the underline of tab stop, The method I use is to Set the color of the underline to white
Code Line13-16
but it has no effect, The result is HTML code
3.
In word file, I need to set the width of the tab stop,
Code Line8
but it has no effect
4.
In word file, Set the font Courier New for all characters
Code Line9-11
but it has no effect
Is there a better solution? Any suggestions are welcome. Thanks in advance
Macro Macro9
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._create
str WordDoc="$desktop$\\test.docx"
VARIANT vWordFile=WordDoc.expandpath
Word.Document doc = app.documents.Add()
doc.DefaultTabStop=app.Application.CentimetersToPoints(0.74) ;;Default tab width
app.Selection.Font.Name = "Courier New"
app.Selection.Font.NameAscii = "Courier New"
app.Selection.Font.Size = 14
;_s.getclip
;;out _s
;_s.findreplace("e0e0e0" "ffffff") ;;Set the underline color to white
;_s.setclip
app.Selection.Paste() ;;Paste text
doc.PageSetup.LeftMargin=app.CentimetersToPoints(1)
doc.PageSetup.TopMargin=app.CentimetersToPoints(1)
doc.PageSetup.RightMargin=app.CentimetersToPoints(1)
doc.PageSetup.BottomMargin=app.CentimetersToPoints(1)
doc.SaveAs(vWordFile)
app.Quit()
run vWordFile
Macro test
int h = id(2210 "Quick Macros")
int y = 10
;Click 5 times, each time adding 16 to y
rep 5
,lef 50 y h
,0.5 ;;wait 0.5 s
,y + 16
;Select text
lef+ 20 15 h
lef- 20 80 h
Posts: 125
Threads: 20
Joined: Jan 2021
01-19-2021, 12:53 AM
(This post was last modified: 01-19-2021, 01:19 AM by macman.)
Now, in any QM code, pressing the ALT + W hotkey saves the code as a word file
There is only two problem left unsolved
1.Sets the color of tab underline
line 12-15
2.Set paragraph border to none
line 26-34
Does anyone know some details of converting VBA code into QM code? thanks a lot
Macro Macro9
Trigger Aw
int w1=id(2213 win("" "QM_Editor"))
men 33354 w1 ;;Copy HTML
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._create
str WordDoc="$desktop$\\test.docx"
VARIANT vWordFile=WordDoc.expandpath
Word.Document doc = app.documents.Add()
;_s.getclip
;;out _s
;_s.findreplace("e0e0e0" "ffffff") ;;Set the underline color to white
;_s.setclip
app.Selection.Paste() ;;Paste text
doc.Content.Font.Name = "Courier New" ;;Set Font
doc.Content.Font.NameAscii = "Courier New"
doc.Content.Font.Size = 10
doc.Content.ParagraphFormat.TabStops.ClearAll ;;Set tab width
doc.DefaultTabStop=app.Application.CentimetersToPoints(0.74)
;;;;Selection.WholeStory
;;;;With Selection.ParagraphFormat
;;;;;;;;.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
;;;;;;;;.Borders(wdBorderRight).LineStyle = wdLineStyleNone
;;;;;;;;.Borders(wdBorderTop).LineStyle = wdLineStyleNone
;;;;;;;;.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
;;;;;;;;.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
;@Set paragraph border to none, Above is word VBA code
;doc.Content.ParagraphFormat.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
doc.PageSetup.LeftMargin=app.CentimetersToPoints(1) ;;set margins
doc.PageSetup.TopMargin=app.CentimetersToPoints(1)
doc.PageSetup.RightMargin=app.CentimetersToPoints(1)
doc.PageSetup.BottomMargin=app.CentimetersToPoints(1)
doc.SaveAs(vWordFile)
app.Quit()
run vWordFile
Posts: 1,338
Threads: 61
Joined: Jul 2006
01-19-2021, 01:37 AM
(This post was last modified: 01-19-2021, 02:50 AM by Kevin.)
for #1 and #2
Macro Macro36
Trigger Aw
men 33354 id(2213 _hwndqm) ;;Copy HTML
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._create
str WordDoc="$desktop$\\test.docx"
VARIANT vWordFile=WordDoc.expandpath
Word.Document doc = app.documents.Add()
_s.getclip("HTML Format")
_s.findreplace(".i{color:#e0e0e0;text-decoration:underline}" ".i{color:#ffffff;text-decoration:underline}") ;;Set the underline color to white
_s.setclip("HTML Format")
app.Selection.Paste() ;;Paste text
doc.Content.Font.Name = "Courier New" ;;Set Font
doc.Content.Font.NameAscii = "Courier New"
doc.Content.Font.Size = 10
doc.Content.ParagraphFormat.TabStops.ClearAll ;;Set tab width
doc.DefaultTabStop=app.Application.CentimetersToPoints(0.74)
app.Selection.WholeStory()
app.Selection.ParagraphFormat.Borders.Item(wdBorderLeft).LineStyle = wdLineStyleNone
app.Selection.ParagraphFormat.Borders.Item(wdBorderRight).LineStyle = wdLineStyleNone
app.Selection.ParagraphFormat.Borders.Item(wdBorderTop).LineStyle = wdLineStyleNone
app.Selection.ParagraphFormat.Borders.Item(wdBorderBottom).LineStyle = wdLineStyleNone
app.Selection.ParagraphFormat.Borders.Item(wdBorderHorizontal).LineStyle = wdLineStyleNone
doc.Content.ParagraphFormat.Borders.Item(wdBorderLeft).LineStyle = wdLineStyleNone
doc.PageSetup.LeftMargin=app.CentimetersToPoints(1) ;;set margins
doc.PageSetup.TopMargin=app.CentimetersToPoints(1)
doc.PageSetup.RightMargin=app.CentimetersToPoints(1)
doc.PageSetup.BottomMargin=app.CentimetersToPoints(1)
doc.SaveAs(vWordFile)
app.Quit()
run vWordFile
Posts: 125
Threads: 20
Joined: Jan 2021
01-19-2021, 03:09 AM
(This post was last modified: 01-19-2021, 03:44 AM by macman.)
The job is perfect . Thank you so much @kevin
This Macro can replace the QM printing function
@ Kevin
QM use Com operate word faster than VBA code?
How to calculate execution time?
Posts: 1,338
Threads: 61
Joined: Jul 2006
measure using perf example
long t1=perf
int i ii
for i 0 1000000
,ii= i
long t2=perf
out t2-t1;;difference in microseconds
;; convert to seconds
double d= t2 - t1
out d/1000000;;difference in seconds
Posts: 125
Threads: 20
Joined: Jan 2021
@ Kevin
A lot of time is wasted loading word
Add an underline above the sub function, Is it difficult to achieve?
Posts: 125
Threads: 20
Joined: Jan 2021
How to convert the following VBA code into QM code?
Sub Addpagenumber()
With ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary)
Set rng = .Range
rng.Text = "Page "
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, wdFieldPage, "Page"
Set rng = .Range
rng.Collapse wdCollapseEnd
rng.Text = " of "
rng.Collapse wdCollapseEnd
ActiveDocument.Fields.Add rng, wdFieldNumPages, "Pages"
Set rng = .Range
rng.Collapse wdCollapseEnd
rng.Text = " total"
.Range.Fields.Update
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
End Sub
Posts: 125
Threads: 20
Joined: Jan 2021
01-21-2021, 05:29 AM
(This post was last modified: 01-21-2021, 06:50 AM by macman.)
Word.Range rng=doc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range
rng.Text = "page "
rng.Collapse(wdCollapseEnd)
doc.Fields.Add(rng wdFieldPage "Page")
rng.Text = " of "
rng.Collapse(wdCollapseEnd)
doc.Fields.Add(rng wdFieldNumPages "Page")
rng.Collapse(wdCollapseEnd)
rng.Text = " total"
doc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range.Fields.Update
doc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
Collapse([`&Direction]).
rng.Collapse(Word.WdCollapseDirection.wdCollapseEnd)
This parameter cannot be set
Posts: 1,338
Threads: 61
Joined: Jul 2006
somethings need to be in a VARIANT
this works not sure if it is 100% correct.
Macro Macro36
Trigger Aw
Word.Range rng=doc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range
rng.Text="page "
VARIANT FieldPage=wdFieldPage
VARIANT Direction=wdCollapseEnd
VARIANT FieldNumPages=wdFieldNumPages
rng.SetRange(rng rng)
rng.Collapse(Direction)
rng.Fields.Add(rng FieldPage)
rng.Collapse(Direction)
rng.SetRange(rng rng)
rng.InsertAfter(" of ")
rng.SetRange(rng rng)
rng.Collapse(Direction)
rng.Fields.Add(rng FieldNumPages)
rng.Collapse(Direction)
rng.SetRange(rng rng)
rng.InsertAfter(" Total ")
rng.SetRange(rng rng)
rng.Collapse(Direction)
doc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range.Fields.Update
doc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
Posts: 125
Threads: 20
Joined: Jan 2021
01-21-2021, 08:39 AM
(This post was last modified: 01-21-2021, 08:39 AM by macman.)
@ Kevin
The work is perfect. Thank you very much for your help
This is a very good case for Word VBA code conversion to QM code
Macro Macro3
men 33354 id(2213 _hwndqm) ;;Copy HTML
typelib Word {00020905-0000-0000-C000-000000000046} 8.0
Word.Application app._create
str WordDoc="$desktop$\\test.docx"
VARIANT vWordFile=WordDoc.expandpath
Word.Document doc = app.documents.Add()
_s.getclip("HTML Format")
_s.findreplace(".i{color:#e0e0e0;text-decoration:underline}" ".i{color:#ffffff;text-decoration:underline}") ;;Set the underline color to white
_s.setclip("HTML Format")
app.Selection.Paste() ;;Paste text
doc.Content.Font.Name = "Courier New" ;;Set Font
doc.Content.Font.NameAscii = "Courier New"
doc.Content.Font.Size = 10
doc.Content.ParagraphFormat.TabStops.ClearAll ;;Set tab width
doc.DefaultTabStop=app.Application.CentimetersToPoints(0.74)
app.Selection.WholeStory()
app.Selection.ParagraphFormat.Borders.Item(wdBorderLeft).LineStyle = wdLineStyleNone
app.Selection.ParagraphFormat.Borders.Item(wdBorderRight).LineStyle = wdLineStyleNone
app.Selection.ParagraphFormat.Borders.Item(wdBorderTop).LineStyle = wdLineStyleNone
app.Selection.ParagraphFormat.Borders.Item(wdBorderBottom).LineStyle = wdLineStyleNone
app.Selection.ParagraphFormat.Borders.Item(wdBorderHorizontal).LineStyle = wdLineStyleNone
doc.Content.ParagraphFormat.Borders.Item(wdBorderLeft).LineStyle = wdLineStyleNone
doc.PageSetup.LeftMargin=app.CentimetersToPoints(1) ;;set margins
doc.PageSetup.TopMargin=app.CentimetersToPoints(1)
doc.PageSetup.RightMargin=app.CentimetersToPoints(1)
doc.PageSetup.BottomMargin=app.CentimetersToPoints(1)
doc.PageSetup.HeaderDistance = app.CentimetersToPoints(0.5)
doc.PageSetup.FooterDistance = app.CentimetersToPoints(0.5)
Word.Range rng=doc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range ;;Add page number
rng.Text="page "
VARIANT FieldPage=wdFieldPage
VARIANT Direction=wdCollapseEnd
VARIANT FieldNumPages=wdFieldNumPages
rng.SetRange(rng rng)
rng.Collapse(Direction)
rng.Fields.Add(rng FieldPage)
rng.Collapse(Direction)
rng.SetRange(rng rng)
rng.InsertAfter(" of ")
rng.SetRange(rng rng)
rng.Collapse(Direction)
rng.Fields.Add(rng FieldNumPages)
rng.Collapse(Direction)
rng.SetRange(rng rng)
rng.InsertAfter(" Total ")
rng.SetRange(rng rng)
rng.Collapse(Direction)
doc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range.Fields.Update
doc.Sections.Item(1).Footers.Item(wdHeaderFooterPrimary).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
doc.SaveAs(vWordFile)
app.Quit()
run vWordFile
Posts: 125
Threads: 20
Joined: Jan 2021
01-21-2021, 10:12 AM
(This post was last modified: 01-21-2021, 12:05 PM by macman.)
The following VBA code can add a horizontal line in front of the line where # sub is located
The following code sometimes works unsteadily, why?
________________________________________________________________________________
Word.Find f=app.Selection.Find
f.ClearFormatting
f.Text="#sub"
rep
if(!f.Execute)
break
app.Selection.ParagraphFormat.Borders.Item(wdBorderTop).LineStyle = wdLineStyleSingle
Sub FindSubAddline()
Selection.Find.ClearFormatting
Selection.Find.Text = "#sub"
Selection.Find.Execute
Selection.ParagraphFormat.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
End Sub
Posts: 125
Threads: 20
Joined: Jan 2021
01-22-2021, 06:25 AM
(This post was last modified: 01-22-2021, 06:26 AM by macman.)
The above code, will search all the results #sub , there will be errors, like the following picture
How to use QM regular expressions to solve this problem?
Posts: 1,338
Threads: 61
Joined: Jul 2006
01-22-2021, 11:44 PM
(This post was last modified: 01-23-2021, 12:01 AM by Kevin.)
this should work for you uses wildcards
Word.Find f=app.Selection.Find
f.ClearFormatting
f.Text="#sub *"
f.MatchWildcards = 1
rep
,if(!f.Execute)
,,break
,app.Selection.ParagraphFormat.Borders.Item(wdBorderTop).LineStyle = wdLineStyleSingle
or maybe even better .. finds #sub that is a specific color
Word.Find f=app.Selection.Find
f.ClearFormatting
f.Font.Color = 4210943
f.Text="#sub"
rep
,if(!f.Execute)
,,break
,app.Selection.ParagraphFormat.Borders.Item(wdBorderTop).LineStyle = wdLineStyleSingle
Posts: 125
Threads: 20
Joined: Jan 2021
01-23-2021, 12:34 AM
(This post was last modified: 01-23-2021, 12:35 AM by macman.)
@kevin
thanks,
finds #sub that is a specific color
This method is good. How to get the value of color ?
f.Font.Color = 4210943
Posts: 1,338
Threads: 61
Joined: Jul 2006
i got the rgb value from qm and then did a macro record in word and looked at the value stored in the word macro
Posts: 125
Threads: 20
Joined: Jan 2021
Good idea
Posts: 1,338
Threads: 61
Joined: Jul 2006
01-23-2021, 12:53 AM
(This post was last modified: 01-23-2021, 02:03 AM by Kevin.)
or can get the rgb value and run this macro to see the color value
int red green blue color
red=255
green=64
blue=64
color=ColorFromRGB(red green blue)
out color
or can simply get the qm color value which is in format 0xBBGGRR and do this
int color2=0x4040FF
out color2
Posts: 125
Threads: 20
Joined: Jan 2021
thanks, QM has many powerful functions
|