Results 1 to 2 of 2

Thread: Can you help me with VB macro plz ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    4

    Question Can you help me with VB macro plz ?

    Hello everyone , is here any one to help me with visual basic macro?
    here is the macro code :
    VB Code:
    1. Attribute VB_Name = "gw_twocolumn"
    2. Sub gw_twocolumn_to_xml()
    3. str_startTime = Time
    4. CRLF = Chr(13) + Chr(10)
    5. str_range = ActiveWindow.RangeSelection.Address()
    6. str_1 = "<line><term>"
    7. str_2 = "</term><defn><trns>"
    8. str_3 = "</trns></defn></line>"
    9. Rem
    10. Rem
    11. Sheets.Add Count:=1, after:=Sheets(1)
    12. Worksheets(1).Activate
    13. Set r = Range(str_range)
    14. For n = 1 To r.Rows.Count
    15.     Worksheets(2).Cells(n, 1) = _
    16.     str_1 & r.Cells(n, 1) & _
    17.     str_2 & r.Cells(n, 2) & str_3
    18. Next n
    19. Worksheets(2).Columns(1).ColumnWidth = 150
    20. Rem
    21. Rem
    22. str_stopTime = Time
    23. double_elapsedTime = (str_stopTime - str_startTime) * 24 * 60 * 60
    24. MsgBox "Range: " & str_range & CRLF & _
    25.         "Elapsed time: " & double_elapsedTime & _
    26.         " sec."
    27. End Sub

    When you open excel file , name one cloumn = term and the second one = defn ,when i run the macro the generated code in excel sheet look like this

    ---------------------------- XML Code Start----------------------------------
    <line><term>rule</term><defn><trns>Control</trns></defn></line>
    <line><term>manage</term><defn><trns>Supervise</trns></defn></line>
    <line><term>management</term><defn><trns>Supervision</trns></defn></line>
    -----------------------------Xml Code end------------------------------------

    this macro is for making a dictionary so if you look at this code closely and look at the grammer point you may understand it well and i want the code to generate somthing like this

    -------------------------------Xml Code start -------------------------------
    <line><term t1="C" t2="CO" id="12">Control</term><defn><abbr lang="noun"></abbr>rule</defn></line>
    <line><term t1="S" t2="SU" id="3">Supervise</term><defn><abbr lang="verb"></abbr>manage</defn></line>
    <line><term t1="S" t2="SU" id="7">Supervision</term><defn>management</defn></line>
    -------------------------------Xml Code end -------------------------------


    Or like this

    --------------------------------Xml Code Start ----------------------------
    <line><term>Control</term><defn><abbr lang="noun"></abbr>rule</defn></line>
    <line><term>Supervise</term><defn><abbr lang="verb"></abbr>manage</defn></line>
    <line><term>Supervision</term><defn>management</defn></line>
    ----------------------------------Xml Code End -----------------------------

    i put the important point in green color

    the important thing is the grammer part i mean to show wether this term is ( verb or noun or adjective etc... )

    I need the macro that what ever i write in excel cloumn it bring that in a code like this

    <abbr lang="( the words in cloumn should come here)"></abbr>


    I will be looking forward to your replies as soon as possible .


    Best regards.
    http://www.realafghan.com

    http://www.realafghan.com/forum

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Can you help me with VB macro plz ?

    Originally posted by badmaghz
    Hello everyone , is here any one to help me with visual basic macro?
    here is the macro code :
    VB Code:
    1. Attribute VB_Name = "gw_twocolumn"
    2. Sub gw_twocolumn_to_xml()
    3. str_startTime = Time
    4.  
    5. [color=green]
    6. '---- vbCrlf (already defined)
    7. [/color]
    8. CRLF = Chr(13) + Chr(10)
    9. str_range = ActiveWindow.RangeSelection.Address()
    10. str_1 = "<line><term>"
    11. str_2 = "</term><defn><trns>"
    12. str_3 = "</trns></defn></line>"
    13. Rem
    14. Rem
    15. Sheets.Add Count:=1, after:=Sheets(1)
    16. Worksheets(1).Activate
    17. Set r = Range(str_range)
    18. For n = 1 To r.Rows.Count
    19.     Worksheets(2).Cells(n, 1) = _
    20.     str_1 & r.Cells(n, 1) & _
    21.     str_2 & r.Cells(n, 2) & str_3
    22. Next n
    23. Worksheets(2).Columns(1).ColumnWidth = 150
    24. Rem
    25. Rem
    26. str_stopTime = Time
    27. double_elapsedTime = (str_stopTime - str_startTime) * 24 * 60 * 60
    28. MsgBox "Range: " & str_range & CRLF & _
    29.         "Elapsed time: " & double_elapsedTime & _
    30.         " sec."
    31. End Sub

    When you open excel file , name one cloumn = term and the second one = defn ,when i run the macro the generated code in excel sheet look like this

    ---------------------------- XML Code Start----------------------------------
    <line><term>rule</term><defn><trns>Control</trns></defn></line>
    <line><term>manage</term><defn><trns>Supervise</trns></defn></line>
    <line><term>management</term><defn><trns>Supervision</trns></defn></line>
    -----------------------------Xml Code end------------------------------------

    this macro is for making a dictionary so if you look at this code closely and look at the grammer point you may understand it well and i want the code to generate somthing like this

    -------------------------------Xml Code start -------------------------------
    <line><term t1="C" t2="CO" id="12">Control</term><defn><abbr lang="noun"></abbr>rule</defn></line>
    <line><term t1="S" t2="SU" id="3">Supervise</term><defn><abbr lang="verb"></abbr>manage</defn></line>
    <line><term t1="S" t2="SU" id="7">Supervision</term><defn>management</defn></line>
    -------------------------------Xml Code end -------------------------------


    Or like this

    --------------------------------Xml Code Start ----------------------------
    <line><term>Control</term><defn><abbr lang="noun"></abbr>rule</defn></line>
    <line><term>Supervise</term><defn><abbr lang="verb"></abbr>manage</defn></line>
    <line><term>Supervision</term><defn>management</defn></line>
    ----------------------------------Xml Code End -----------------------------

    i put the important point in green color

    the important thing is the grammer part i mean to show wether this term is ( verb or noun or adjective etc... )

    I need the macro that what ever i write in excel cloumn it bring that in a code like this

    <abbr lang="( the words in cloumn should come here)"></abbr>


    I will be looking forward to your replies as soon as possible .


    Best regards.
    How about spreadsheet columns:
    Term - Defn - Grammar

    Then a loop to get all the selected rows, and an inside loop to get the columns...
    VB Code:
    1. '---- open the file for output first
    2. '---- then set the sht (worksheet) to the active sheet
    3. '---- set lngStartRow to the topmost row of the selection
    4. '---- set lngMaxRow to the bottommost row of the selection
    5. set sht = activesheet
    6.  
    7. for lngRow = lngStartRow to lngMaxRow
    8.     strOp = "<line>"
    9.  
    10.     for lngCol = 1 to 3
    11.         select case lngcol
    12.              case 1
    13.                 strop = strOP & "<term>"
    14.              case 1
    15.                 strop = strOP & "<defn>"
    16.              case 1
    17.                 strop = strOP & "<grammar>"
    18.          end select
    19.  
    20.          strOp=strOp & sht.cells(lngRow,lngCol).value
    21.  
    22.         select case lngcol
    23.              case 1
    24.                 strop = strOP & "</term>"
    25.              case 1
    26.                 strop = strOP & "</defn>"
    27.              case 1
    28.                 strop = strOP & "</grammar>"
    29.          end select
    30.          
    31.     next
    32.     strOp = strOp & "</line>"
    33.  
    34. '----sends line to file (saving)
    35.     print #1, strOp
    36. next

    Or something like that...


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

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



Click Here to Expand Forum to Full Width