• Converting Word Perfect Macro to Microsoft Word

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Converting Word Perfect Macro to Microsoft Word

    Author
    Topic
    #507302

    Hi,

    I have been trying to convert this WP macro to word but no luck so far.
    It basically reads the *.DAT file, searches specific lines and replaces it with pre-set code title with numbers i.e 3267:

    I look forward to receiving some help.
    Thank you in advance.

    Here is the macro;

    Application (WordPerfect; “WordPerfect”; Default!; “EN”)
    FileOpen (Filename: “C:Usersodfcheq.dat”)
    Font (Name: “Courier New “; Family: 14593; Attributes: FontMatchNormal!; Weight: 90; Width: WidthUnknown!; Source:
    DRSFile!; Type: TrueType!; CharacterSet: FontMatchASCII!)
    FontSize (FontSize: 0.153″)
    MarginTop (MarginWidth: 0.5″)
    MarginBottom (MarginWidth: 0.5″)
    MarginLeft (MarginWidth: 0.5″)
    MarginRight (MarginWidth: 0.5”)
    SearchString (StrgToLookFor: “[Paper Sz/Typ]”)
    ReplaceString (RplcStrg: “”)
    ReplaceForward (SearchMode: Extended!)

    PosDocTop ()
    SearchString (StrgToLookFor: “[HRt][HRt]”)
    ReplaceString (RplcStrg: “[HRt]”)
    ReplaceForward (SearchMode: Extended!)
    PosDocTop ()

    SelectLineDown ()
    SelectLineDown ()
    DeleteCharNext ()
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “FOOD BANK DONATION QTY:”)
    ReplaceString (RplcStrg: “FOOD BANK DONATION 3267″)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: ” ASSIGNMENT ON HOLD[HRt]”)
    ReplaceString (RplcStrg: “”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “NO ASSIGNMENTS ON FILE[HRt]”)
    ReplaceString (RplcStrg: “”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “QUOTA PAYMENT RECD QTY: = .0”)
    ReplaceString (RplcStrg: “QUOTA PAYMENT RECD = “)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()

    SearchString (StrgToLookFor: “QEX Srv Charge QTY: = .0”)
    ReplaceString (RplcStrg: “QEX Srv Charge 717 = “)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “QEX Srv Charge .0”)
    ReplaceString (RplcStrg: “QEX Srv Charge 717 = “)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “Organic Milk Premium 32692 = “)
    ReplaceString (RplcStrg: “Organic Milk Premium 32692 =”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “DFO ‑ TTR PAYMENT =”)
    ReplaceString (RplcStrg: “DFO ‑ TTR PAYMENT 536 =”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “DAIRY PRODUCTS QTY: = .0”)
    ReplaceString (RplcStrg: “DAIRY PRODUCTS 931 = “)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “JERSEY ONTARIO =”)
    ReplaceString (RplcStrg: “JERSEY ONTARIO 536 =”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “AYRSHIRE CATTLE CLUB =”)
    ReplaceString (RplcStrg: “AYRSHIRE CATTLE CLUB 536 =”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “ASSIGNMENTS‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑‑[HRt]**”)
    ReplaceString (RplcStrg: “**”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()

    SearchString (StrgToLookFor: “DIPPER PURCHASE QTY: = .0”)
    ReplaceString (RplcStrg: “DIPPER PURCHASE 5351 = “)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “PERSONAL COMPENSATION AGENCY =”)
    ReplaceString (RplcStrg: “PERSONAL COMPENSATION AGENCY 93 =”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “Kgs QTY: = .0”)
    ReplaceString (RplcStrg: “Kgs = “)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “Kgs = $ 15.00‑”)
    ReplaceString (RplcStrg: “Kgs 717 = $ 15.00‑”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: “[HRt][HRt]”)
    ReplaceString (RplcStrg: “[HRt]”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()
    PosDocTop ()
    SearchString (StrgToLookFor: ” *****”)
    ReplaceString (RplcStrg: “*****”)
    ReplaceForward (SearchMode: Extended!)
    PosDocTop ()
    SearchString (StrgToLookFor: “FARM INSPECTION CHARGE QTY: = .0 “)
    ReplaceString (RplcStrg: “FARM INSPECTION CHARGE 717 = “)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “GAY LEA FOODS CO‑OP LIMITED =”)
    ReplaceString (RplcStrg: “GAY LEA FOODS CO‑OP LIMITED N2 =”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “ORGANIC MEADOW CO‑OPERATIVE =”)
    ReplaceString (RplcStrg: “ORGANIC MEADOW CO‑OPERATIVE N2 =”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “MILK HOUSE SUPPLIES QTY: = .0 $”)
    ReplaceString (RplcStrg: “MILK HOUSE SUPPLIES 5351 = $”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “QTY: = .0 $ 5.00‑”)
    ReplaceString (RplcStrg: ” 717 = $ 5.00‑”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “QTY: = .0 $ 15.00‑”)
    ReplaceString (RplcStrg: ” 717 = $ 15.00‑”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “QTY: = .0 $”)
    ReplaceString (RplcStrg: ” N11 = $”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “NO ASSIGNMENTS ON FILE “)
    ReplaceString (RplcStrg: “”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()
    SearchString (StrgToLookFor: “QUOTA PAYMENT RECD QTY: =”)
    ReplaceString (RplcStrg: “QUOTA PAYMENT RECD =”)
    ReplaceForward (SearchMode: Extended!)
    PosDocBottom ()

    PosDocTop ()

    Viewing 16 reply threads
    Author
    Replies
    • #1581939

      Some pages found by a search, looks like not simple:
      https://duckduckgo.com/?q=import+wordperfect+macro+into+wor&t=h_&atb=v24&ia=web

      Before you wonder "Am I doing things right," ask "Am I doing the right things?"
    • #1581942

      WordPerfect macros do not translate.
      (That is a full stop at the end of this statement.)

      The two programs do things in very different ways.

      Try recording macro that does this in one file. Then come back here with the vba code for help.
      I do not know that Word will open and edit a DAT file.

      http://addbalance.com/word/wordperfect.htm

      I’ve written 800-line WP macros but it has been a long time since I’ve done anything of the sort.

    • #1581943

      The macro needs to be created from scratch in VBA. It doesn’t look particularly onerous and is along the lines of the following aircode

      Code:
      Sub WhoDat()
        Dim aDoc As Document
        Set aDoc = Documents.Open(FileName:="C:Usersodfcheq.dat", ConfirmConversions:=False, Format:=wdOpenFormatAuto)
        
        With aDoc.Range.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchAllWordForms = False
          .MatchSoundsLike = False
          .MatchWildcards = False
          
          .Execute Replace:=wdReplaceAll, FindText:="[HRt][HRt]", ReplaceWith:="[HRt]"
          .Execute Replace:=wdReplaceAll, FindText:="FOOD BANK DONATION QTY:", ReplaceWith:="FOOD BANK DONATION 3267"
          .Execute Replace:=wdReplaceAll, FindText:=" ASSIGNMENT ON HOLD[HRt]", ReplaceWith:=""
          .Execute Replace:=wdReplaceAll, FindText:="NO ASSIGNMENTS ON FILE[HRt]", ReplaceWith:=""
          'etc
          
        End With
      End Sub

      Now, I’m guessing that [HRt] in Wordperfect’s macro is probably code for a ‘hard return’. If that is the case, the lines that mention it will need to replace it with ^p
      eg .Execute Replace:=wdReplaceAll, FindText:=”[HRt][HRt]“, ReplaceWith:=”[HRt]” becomes
      .Execute Replace:=wdReplaceAll, FindText:=”^p^p“, ReplaceWith:=”^p

      • #1582257

        Andrew: This code below do not run in my machine. What is Sub WhoDat(), the error starts with the first line in the command.
        Thank you.

        The macro needs to be created from scratch in VBA. It doesn’t look particularly onerous and is along the lines of the following aircode

        Code:
        Sub WhoDat()
          Dim aDoc As Document
          Set aDoc = Documents.Open(FileName:="C:Usersodfcheq.dat", ConfirmConversions:=False, Format:=wdOpenFormatAuto)
          
          With aDoc.Range.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = False
            .MatchWholeWord = False
            .MatchAllWordForms = False
            .MatchSoundsLike = False
            .MatchWildcards = False
            
            .Execute Replace:=wdReplaceAll, FindText:="[HRt][HRt]", ReplaceWith:="[HRt]"
            .Execute Replace:=wdReplaceAll, FindText:="FOOD BANK DONATION QTY:", ReplaceWith:="FOOD BANK DONATION 3267"
            .Execute Replace:=wdReplaceAll, FindText:=" ASSIGNMENT ON HOLD[HRt]", ReplaceWith:=""
            .Execute Replace:=wdReplaceAll, FindText:="NO ASSIGNMENTS ON FILE[HRt]", ReplaceWith:=""
            'etc
            
          End With
        End Sub

        Now, I’m guessing that [HRt] in Wordperfect’s macro is probably code for a ‘hard return’. If that is the case, the lines that mention it will need to replace it with ^p
        eg .Execute Replace:=wdReplaceAll, FindText:=”[HRt][HRt]“, ReplaceWith:=”[HRt]” becomes
        .Execute Replace:=wdReplaceAll, FindText:=”^p^p“, ReplaceWith:=”^p

    • #1582306

      What version of Word are you using?

      • #1582475

        What version of Word are you using?

        I am using Microsoft Office 2010.

    • #1582402

      Andrew, when I look at and copy and paste line 2 of the code from your post, I get this:

      Set aDoc = Documents.Open(FileName:=”C:Usersodfcheq.datnfirmConversions:=False, Format:=wdOpenFormatAuto)

      There may be something odd going on with this string, because when I responded and looked at your original post, displayed below my Reply box, this line in your post was correct:

      Set aDoc = Documents.Open(FileName:=”C:Usersodfcheq.dat, ConfirmConversions:=False, Format:=wdOpenFormatAuto)

      I don’t know what’s going wrong, but if Tigris copied and pasted as I did, it may be the reason he had an issue with your code.

      Kim

    • #1582518

      Tigris

      Following Kim’s suggestion, can you confirm that the text you pasted reads the same as the code shown in my post. This website sometimes changes the text slightly when you paste it into Word and you need to repair odd lines because of odd spacing or line breaks that weren’t intended.

      If that doesn’t reveal any issues, show us what the error message is and what line is highlighted when you try to debug.

    • #1582570

      You know, the string in my own post isn’t displaying or copying and pasting properly–even the one I claimed to be accurate.

      45849-code-not-right-on-forum

      So I’m going to paste what the line should be here, without any format codes:

      Set aDoc = Documents.Open(FileName:=”C:Usersodfcheq.dat, ConfirmConversions:=False, Format:=wdOpenFormatAuto)

      And if that ultimately doesn’t look right, here’s a picture of what it should look like so you can type it out:

      45851-picture-of-code

      Whew.

    • #1582572

      One last post, just so y’all won’t think I’m nuts (about this anyway)…

      Here’s another screenshot of the line I just said (and captured) that wasn’t displaying correctly:

      45852-correct-code-from-just-a-few-seconds-later

      It seems to have straightened itself out with a page refresh. Definitely something wrong with the display. Could be mine, could be formatted text on the forum.
      Just sayin’ I’m not :bananas:

      • #1582756

        Hi Kim & Andrew,

        This web changes the text when copy/paste in here. I managed to open the file using Kim’s advice on that. Ditto mark was missing after odfcheq.dat so I inserted that and it opens the file but very messy and i don’t think it replaces them at all. Can we also choose the font/format size when opening the file because font 9 or 9.5 is the max that numbers can match the lines. Can I choose “calibri” to open with for example?

        I ran it for “food bank donation qty” and it didn’t replace it with “Food Bank Donation 3267”
        I am actually going to attach them in here so you can get an idea.
        attached: capture of the code.
        I would also attach “odfcheq.dat file but this site says it is not a valid file and do not let uploading…

        Thanks,

      • #1582757

        Thank you for your help. I did open the file but it does not replace the lines with suggested ones. Please see my reply for you and Andrew.

    • #1582761

      Tigris,

      A long time ago I worked extensively with WordPerfect and my recollection is that .dat was an extension WordPerfect used for the purpose of designating them as data files, but there was nothing particularly different between a .dat file and a .wpd file. You might try just copying your .dat file to another name, changing the extension to .wpd. Does this forum allow you to upload .wpd files?

      Failing that, can you do a screen capture of part of the odfcheq.dat file, just so we can get an idea of what’s in it? My suspicion is that there’s a fairly simple issue that’s keeping the find/replace function from working.

      Kim

    • #1582768

      The find and replace is exact so you need to pay attention to ALL the details.
      You said…
      I ran it for “food bank donation qty” and it didn’t replace it with “Food Bank Donation 3267”

      But your screen capture shows a line of text looking for a string that ends with a ‘:’. Does that exact string even exist in the the document?

      Note also that the capitalisation might be important if you have subsequently fiddled with the MatchCase line of the code.

      • #1582815

        Yes but when I ran the macro it does nothing but to open the file in Microsoft Word. I tried to upload the .DAT file in here but this web does not accept it. The same counts for .wpd extension…
        is there any other suggestion on how to upload so you can also get to see the data file we are talking about.
        thanks,

      • #1582827

        ok. I am attaching the odfcheq.dat file here (with .doc extension).
        Please take a look.

    • #1582816

      Change the file extension to .doc and it should load here happily. The file extension is meaningless if we know what the file type is.

      • #1582842

        You were right. It now worked. However it opens the file with font size 10.5 which is large.
        Is there a way to open it with size 9.5.
        I used the following code within your code but did not return success so far.

        With Selection.Font
        .Name = “Calibri”
        .Size = 9.5
        .Bold = False
        .Italic = False

    • #1582845

      Andrew: You were right. It now works, however it opens the file with font size 10.5.
      Is there a way to open it with desired font format? I used the following code within your code but it did not
      return success so far.

      With Selection.Font
      .Name = “Times New Roman”
      .Size = 9.5
      .Bold = False
      .Italic = False

    • #1582870

      I would assume the font size comes from the original file but once the document is open then you can change it all
      With ActiveDocument.Range.Font
      .Size = 9.5
      .Name = “Times New Roman”
      End With

      It is best to avoid using the Selection object where you can. My code didn’t select anything so Selection would be empty unless you actually selected some content before running your code.

    • #1583127

      Andrew: Thank you very much for all your helps. I managed to write it and everything works fine now.

    • #1584500

      Andrew: I think I need a help with wordperfect’s hard return as you mentioned it.
      What I need is that when I open the ODFCHEQ.DAT file I do not want the farm details to be in different pages rather in one page. There can be more than one farm in each page but not when farm
      details goes to another page.
      As well is there a way to remove the “BUTTERFAT PREMIUM” from the cheque if the amount paid ($) is zero.
      Also even if there is amount paid I do not want to see the weight “kgs” from “BUTTERFAT PREMIUM”
      I am attaching my macro and the *.dat file so that you can see what I am trying to fix recently.

      I really appreciate it if you can help me out or anyone else in this forum.
      Thank you,

      Note: I saved them in *.docx format as this site doesn’t let me upload *.dotm or *.DAT file extensions.

    • #1584580

      I think you need to convert all the multiple spaces to a single tab early in the code so that small variations in the number of spaces doesn’t bite any of the replacements. I fiddled with your code to show you how that works and how the [Hrt] is treated in Word. Note you will need to continue those patterns into your subsequent lines.

      Code:
      Sub MilkChequeFormat()
      
        Dim aDoc As Document
        'Set aDoc = Documents.Open(FileName:="C:DocumentsODFAPMilk Chequesodfcheq.dat", ConfirmConversions:=False, Format:=wdOpenFormatAuto)
        Set aDoc = ActiveDocument
        With aDoc.Range.Find
          .ClearFormatting
          .Replacement.ClearFormatting
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchAllWordForms = False
          .MatchSoundsLike = False
          
          .MatchWildcards = True
          .Execute Replace:=wdReplaceAll, FindText:=" {2,}", ReplaceWith:="^t" 'replace 2 or more spaces with a tab
          .Execute Replace:=wdReplaceAll, FindText:="^tASSIGNMENTS-{2,}^13", ReplaceWith:="" 'note ^13 is a paragraph mark and works if wildcards = True
          
          .MatchWildcards = False
          .Execute Replace:=wdReplaceAll, FindText:="^t^p", ReplaceWith:="^p"  '^t is a tab, ^p is a paragraph mark but doesn't work if wildcards = True
          .Execute Replace:=wdReplaceAll, FindText:="^p^p", ReplaceWith:="^p"
          .Execute Replace:=wdReplaceAll, FindText:="NO ASSIGNMENTS ON FILE^p", ReplaceWith:=""
          .Execute Replace:=wdReplaceAll, FindText:="FOOD BANK DONATION^tQTY: =", ReplaceWith:="FOOD BANK DONATION^t3267 ="
          .Execute Replace:=wdReplaceAll, FindText:="QUOTA PAYMENT RECD^tQTY: =^t.0", ReplaceWith:="QUOTA PAYMENT RECD^t=^t"
      • #1585288

        When applying these changes it did not bring me anywhere. It looks messier than before.
        If you look at the original macro the lines are well aligned for each item in the cheque, but not with this one.

        I appreciate your help. It was a good try but for now the earlier version works better for me.
        Thank you,

    • #1585324

      The alignment is not important until you convert the content to columns. You will find that replacing the variable number of multiple spaces with a single tab allows you to get this information into a tabular format much easier. I thought that was the purpose of doing all of this work.

      You are on the right track and it is just a matter of tinkering with the search and replace steps to get it matching what you wanted.

    Viewing 16 reply threads
    Reply To: Converting Word Perfect Macro to Microsoft Word

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: