+ Reply to Thread
Results 1 to 11 of 11

How to combine 2 macros

  1. #1
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    How to combine 2 macros

    Hi Everyone . . .

    Well, I probably have a odd request, but then I think I'm just different ?

    I have an Excel Workbook with Col. A approximately 1/8" wide. The formatting of this col is that the cells are set to have the typing fit into the cell, therefore it becomes so small that no one can read it. Just what I wanted. If the user needs to read what's in the cell, they can click on the cell and read it in the formula bar.

    Col. B is approximately 2" wide

    1st, the user enters the Path and File name, with extension, into cell A34(example).

    2nd, the user types in a File Name that they will best understand into cell B34.

    The Workbook is now saved.

    When the user wants to open that file, they click on the Name . . . Col B34 - Easily recognized by the user.

    They then click either the Button that say's "Open Excel File" -or- "Open Word File.

    The macro automatically moves the selection over to column A, then the file is opened.

    Now what I need

    I want to use just 1 button and I will name it "OPEN"

    The 2 below macros work excellant and I still need the functionality of each. What I want is that 1st it trys to see if it is an excel file and if so, opens the file and stops.

    If the macro determines that it is not an Excel file, the macro then goes to the Word macro and determines if it really is a Word file and if so, opens the file and stops.

    NOTE: I want to point out that I still need all the checking etc that the 2 macros currently do.

    Here are the macros

    OPEN EXCEL FILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    Please Login or Register  to view this content.


    OPEN WORD FILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

    Please Login or Register  to view this content.
    That's It . . .

    I really enjoy working with all of you at Excel Forum Thank You Very Much. Everyone has been great
    Last edited by Launchnet; 03-14-2009 at 09:10 PM.
    Thanks for helping . . .
    Matt @ Launchnet

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: How to combine 2 macros

    Try using a 3rd macro that calls either of the other 2 macros
    attach code to 1 button

    Add or remove file extentions as required

    Please Login or Register  to view this content.
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to combine 2 macros

    Good Morning Where Ever You Are . . .

    Thanks for your reply.

    I like the idea very much.

    Problem . . . The extension is not being recognized.

    I believe that the reason may be what is actually in the cell . . .

    The cell holds both the Path and the filename with extension

    Example: c:\mymenu\matt10.xls or c:\mymenu\mywordfiles\mattToday.doc

    I even tried moving the activecell 1 column to the left where the path & filename is located, prior to running the macro. Still doesn't work.

    Hopefully, this can help you.

    I still need your help, but I sure like your idea.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: How to combine 2 macros

    The activecell needs to be the cell containing the string. The code picks up the last 3 characters of the string.

    Attach an example workbook.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to combine 2 macros

    Hi RoyUK . . .

    Haven't heard from you in a long time. Thanks for your previous help.

    Simply put a path & filename.xls in any cell on any workbook
    such as c:\mymenu\myfiles\matt10.xls Or any file name.

    Select that cell and then step thru the macro. It does not read the extension. It skips right over that line of code.



    I still have one other application in process. If you get a chance, can you take a look. I need this finished within 2 weeks at the latest.

    Link to Excel Forum.
    http://www.excelforum.com/showthread...54#post2048354

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: How to combine 2 macros

    It works without the Ucase
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: How to combine 2 macros

    Oops I used the wrong command of UCase instead of LCase

    Select Case statements are Upper/Lower case sensitive and because the testing was converting the result to upper case letters and comparig them to lower case it failed to reconize the extentions

    I use the Lcase command to convert the active cell text to the same format that I am testing for
    xls is not the same as XLS or xLs or xLS etc


    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to combine 2 macros

    Gentlemen . . .

    It works perfect.

    In testing, I found that I could cause an error if the user selected any of the odd columns. Basically these OR statements are all that they could select in error, but it would be nice if a > sign could be added in front of the 11.


    Please Login or Register  to view this content.
    Can one of you give me a hand with the correct syntax. I looked in help and couldn't find anything about it.
    Last edited by mudraker; 03-14-2009 at 09:14 PM.

  9. #9
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to combine 2 macros

    I just used
    Please Login or Register  to view this content.
    . . . and this works, but I'm at a loss for OR & AND don't work

  10. #10
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: How to combine 2 macros

    Personally I prefer to use Select case commands when testing the same cell, variable etc for different results.

    It is also more eficient than using If and Or & ELseIf statements

    Please Login or Register  to view this content.
    To use the If command correctly you would need
    Please Login or Register  to view this content.
    Last edited by mudraker; 03-14-2009 at 08:50 PM.

  11. #11
    Valued Forum Contributor
    Join Date
    09-04-2007
    Location
    Ontario, Ca
    Posts
    624

    Re: How to combine 2 macros

    Thank you. It works.

    I also understand the or usage now.

    Many thanks again.

+ 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