+ Reply to Thread
Results 1 to 15 of 15

Problem Running Macro for Completed Code

  1. #1
    Registered User
    Join Date
    06-18-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Problem Running Macro for Completed Code

    Hello,
    Below is some code that will change a selected cell of html text and convert it to formatted text.
    I have created a macro and inserted this code into the designated area under VBA but I still cannot seem to get it working.

    Whenever I use the macro, submacro1 is highlighted and I receive an error saying "compile error: expected end sub"

    Any help would be greatly appreciated


    thanks,

    -vargs

    Attached is the file where I am testing this macro

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Problem Running Macro for Completed Code

    Your first 2 lines are both Sub-routine definitions - you have to close 1 definition before you open another.

    Try this:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-18-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Problem Running Macro for Completed Code

    Thanks for the response,

    I added in that code but for some reason after I close out of VBA, I click on Macros to run it but I have to manually type in Macro1 and run to execute the code.

    Shortly thereafter, I receive the error "argument not valid"
    I attached a macro enabled worksheet of my example which can better explain the problem I am having.

    thanks,

    -vargs
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Problem Running Macro for Completed Code

    You can't run Macro1 from the macro dialogue because it now requires an argument (the target range). Do you want the macro to run automatically when the sheet is updated, or do you want it to be run manually over a selected range?

  5. #5
    Registered User
    Join Date
    06-18-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Problem Running Macro for Completed Code

    It would be perfect to have a macro that is manually run over 1 cell.

    thanks again,

    -vargs

  6. #6
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Problem Running Macro for Completed Code

    By 1 cell, do you mean the currently selected cell?

  7. #7
    Registered User
    Join Date
    06-18-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Problem Running Macro for Completed Code

    Yes that would be perfect if it was the selected cell

  8. #8
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Problem Running Macro for Completed Code

    No problem, try this:

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-18-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Problem Running Macro for Completed Code

    Thanks,

    I tried it out and got a different error this time. When I click Continue(f 5) in visual basic it highlighted the code "objData As DataObject" and then gave me a pop-up saying "Compile error: User-Defined type not defined."

    please let me know what I may doing wrong

    regards,

    -vargs

  10. #10
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Problem Running Macro for Completed Code

    When you say you created this macro .... well, without being too indelicate, you've actually adapted something that you found somewhere, haven't you?

    You're using the clipboard to do something that you could do far more directly, without relying on using an object type which, as far as I can see, only applies to user forms (which you're not using).

    Do you actually need to record the text as being Unicode format, or do you just need to replace the contents of the cell with the plain text?

    See if the following does what you're after ...

    Please Login or Register  to view this content.
    Last edited by Andrew-R; 08-10-2010 at 02:48 PM.

  11. #11
    Registered User
    Join Date
    06-18-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Problem Running Macro for Completed Code

    Forgive me, at no point did I ever want it to be understood that I wrote this code.

    This code is borrowed and here is the original thread from where it came from
    http://www.dailydoseofexcel.com/arch...l-in-cells-ii/

    Ultimately what I want to do is have an excel sheet with two macro buttons.

    These are the tasks I wanted to accomplish with the use of these macros:

    1) When one selects the cell full of Formatted text including new lines bold lettering and font size differences, they can select this macro that will convert that same format into an HTML representation of whatever was selected.

    2) Likewise, if I wanted to make some major adjustments to that code, I would like the option to press another macro and convert that html code back into the formatted text with bold lettering, letter size differences, and multiple rows.

    Sorry for any confusion that this may have caused you,
    I just wanted to find a way to make these macros work.

    thanks,

    -vargs

  12. #12
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Problem Running Macro for Completed Code

    I'm no HTML wizard, so I think I've probably helped you as much as I can on this one, but it looks like you've set yourself a very complex task and I gather that you're very new to Excel macros.

    Perhaps you could try selecting a cell with some HTML text in it and copying it and then use paste special to see if it will paste it as Unicode - run the macro recorder and see what it comes up with. Ultimately, however, it might be easier to just manually cut and paste-special every time you need this function.

    Best of luck - let us know how it goes and sorry I can't help further.

  13. #13
    Registered User
    Join Date
    06-18-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Problem Running Macro for Completed Code

    Thank you for your help
    I appreciate it.

    -vargs

  14. #14
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Problem Running Macro for Completed Code

    As a quick follow-up, a swift Google search told me that the dataobject type is included in the Excel forms library, so to use DataObject you have to:

    1. Go to the Visual Basic editor in Excel.

    2. From the "Tools" menu select "References"

    3. Click "Browse" and then find the file FM20.DLL, which should be in the \Windows\System32 directory.

    4. Click OK.

    With that your original code should work, but you'd have to repeat this process on every machine you wanted your macro to run on.

    See if that gets you any further.

  15. #15
    Registered User
    Join Date
    06-18-2010
    Location
    Dallas
    MS-Off Ver
    Excel 2007
    Posts
    59

    Re: Problem Running Macro for Completed Code

    Thanks for the post,

    I tried that but nothing changed.
    It's ok, I think i will just find a program to automatically convert to HTML code instead.

    Thank you so much for your patience and assistance.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1