Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    New Lounger
    Join Date
    Oct 2016
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Converting Word Perfect Macro to Microsoft Word

    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:\Users\odfcheq.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 ()

  2. #2
    Silver Lounger
    Join Date
    Mar 2014
    Location
    Forever West
    Posts
    2,077
    Thanks
    0
    Thanked 259 Times in 248 Posts
    Some pages found by a search, looks like not simple:
    https://duckduckgo.com/?q=import+wor...atb=v24&ia=web

  3. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,049
    Thanks
    124
    Thanked 119 Times in 116 Posts
    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.
    Charles Kyle Kenyon
    Madison, Wisconsin

  4. #4
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    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:\Users\odfcheq.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"
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  5. #5
    New Lounger
    Join Date
    Oct 2016
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

    Quote Originally Posted by Andrew Lockton View Post
    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:\Users\odfcheq.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"

  6. #6
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    What version of Word are you using?
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  7. #7
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts
    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:\Users\odfcheq.datnfir mConversions:=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:\Users\odfcheq.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

  8. #8
    New Lounger
    Join Date
    Oct 2016
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Andrew Lockton View Post
    What version of Word are you using?
    I am using Microsoft Office 2010.

  9. #9
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    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.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  10. #10
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts
    You know, the string in my own post isn't displaying or copying and pasting properly--even the one I claimed to be accurate.

    code not right on forum.jpg

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

    Set aDoc = Documents.Open(FileName:="C:\Users\odfcheq.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:

    picture of code.jpg

    Whew.

  11. #11
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts
    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:

    correct code from just a few seconds later.jpg

    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

  12. The Following User Says Thank You to kmurdock For This Useful Post:

    Tigris (2016-10-27)

  13. #12
    New Lounger
    Join Date
    Oct 2016
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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,
    Attached Images Attached Images

  14. #13
    New Lounger
    Join Date
    Oct 2016
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  15. #14
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts
    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

  16. #15
    Super Moderator
    Join Date
    Jan 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    3,852
    Thanks
    4
    Thanked 259 Times in 239 Posts
    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.
    Andrew Lockton, Chrysalis Design, Melbourne Australia

  17. The Following User Says Thank You to Andrew Lockton For This Useful Post:

    Charles Kenyon (2016-10-29)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •