+ Reply to Thread
Results 1 to 19 of 19

Passing Parameters t excel Macro

  1. #1
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Passing Parameters t excel Macro

    Hi,

    I am workin gon a code in which start date and end date needs to passed to vb code.

    Start dates and End dates are passed from a vbs file .
    The vbs code is written below:

    Set objExcel = CreateObject("Excel.Application")
    With objExcel
    .Workbooks.Open "C:\emailfetch\FetchEmails.xlsm"
    .Visible = True
    .Run "FolderTraverse",Now-1,Now
    .ActiveWorkbook.Close True
    .Quit
    End With

    Here parameters are passed as Now and Now -1 but with this format dates are limited to some specific scenario.

    How can I pass dates which are not in the Now and Now-1 format.I want to pass dates in more flexible ways.
    Any pointer will be appreciated


    Regards
    Rakesh

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Passing Parameters t excel Macro

    What is more flexible way?
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    By means of more flexible way I mean if I want to pass dates of today and yesterday then Now and Now-1 will be fine.
    What if I want to pass dates like 10-Aug-2013 & 01-Mar-2014.

    How such dates will be entered (Now and Now-1,-2,-3 are not suitable as per my requirement.)

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Passing Parameters t excel Macro

    Hi

    I'd be inclined to pass the date serial number. e.g.

    Please Login or Register  to view this content.
    or if the data is in a cell then use the cell value in the cLng() syntax
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  5. #5
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    Hi Richard,

    Scenario is like below:
    Start dates and end dates are passed like:
    .Run "FolderTraverse",Now-1,Now

    These dates will be passed to a code in VB-->Sub FolderTraverse (a,b)...this code is a part of VB ,based on the dates received further calculation will be done

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Passing Parameters t excel Macro

    Quote Originally Posted by Rakeshnegi01 View Post
    Hi Richard,

    Scenario is like below:
    Start dates and end dates are passed like:
    .Run "FolderTraverse",Now-1,Now

    These dates will be passed to a code in VB-->Sub FolderTraverse (a,b)...this code is a part of VB ,based on the dates received further calculation will be done
    I understand that, but what's your question, (or problem) with the solution I gave you>

  7. #7
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    Hi Richard,

    I am using dates as .Run "FolderTraverse",cLang(DateSerial(1,3,2014)),cLang(DateSerial(2,3,2014))
    After executing I am getting following error:
    Run time error type mismatch Clang.

    And output is getting fetched from dates 04-mar-2014 to 28Feb2014 instead between 1 and 2 March

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Passing Parameters t excel Macro

    It is CLng not CLang
    Also dateserial arguments are Year, Month, Day and not Day, Month, Year.

  9. #9
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    Quote Originally Posted by Izandol View Post
    It is CLng not CLang
    Also dateserial arguments are Year, Month, Day and not Day, Month, Year.
    Hi Izandol,

    Thanks for correcting me.
    It works,thanks a lot again

  10. #10
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    Hi Guys,

    Back again with queries...
    I am executing a batch file whose Contents are
    1.Date.Vbs
    2.Makezip.vbs
    3.mailsend.cmd
    I am passing dates parameter from Date.vbs to a vb code ,like below
    .Run "FolderTraverse",cLng(DateSerial(2014,3,1)),cLng(DateSerial(2014,3,4))

    Now the scenario is I am required to pass these dates from a text file instead of vbs file.
    Please provide some pointers.

    TIA
    Rakesh

  11. #11
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Passing Parameters t excel Macro

    Hi,

    Do you mean the dates are contained in a text file? In which case can I suggest that you open the file, or link to it and grab the dates in a date variable and pass the variable.

  12. #12
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    Could you please help how to implement that

  13. #13
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Passing Parameters t excel Macro

    Hi

    What have you tried so far? Use the macro recorder in the first instance to capture the basic macro code, then review it and edit as necessary.

  14. #14
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    Hi Richard,

    When you say grab the dates in a date variable ,should I grab these date in text file from user via console or entered inside text file.
    And .txt file will be opened if we enter the name of that file in .bat file.

  15. #15
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Passing Parameters t excel Macro

    I meant that you should open the txt file from within an Excel macro and then set the variable that you've already dimensioned to the relevant cell in the txt file you've opened. Once you've done that you can close the txt file.

  16. #16
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    I do not want to open file in the middle of operation .All these scripts need to be scheduled for some specific time so dates should be mentioned initially not in the middle after the files open .
    I need a text file where I can enter dates in the starting and then execute my code.

  17. #17
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Passing Parameters t excel Macro

    Quote Originally Posted by Rakeshnegi01 View Post
    I do not want to open file in the middle of operation .All these scripts need to be scheduled for some specific time so dates should be mentioned initially not in the middle after the files open .
    I need a text file where I can enter dates in the starting and then execute my code.
    In that case I don't understand. I was under the impression that the txt file contained a value that you wanted to pass as a parameter in your code. Which is why I couldn't understand your reluctance to get your macro to open the txt file, grab the value in a variable and immediately close the txt file.

    You'll need to explain your exact process.

  18. #18
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    Scenario is like this.
    I will run execute.bat
    this bat file contains
    Date.vbs
    Makezip.vbs
    mailsend.cmd

    Date.vbs opens a file FetchEmails.xlsm and Pass dates to that vb code inside FetchEmails.xlsm
    On the basis of these dates mails will fetch from outlook inexcel ,then makezip.vbs makes zip of those fetch mails and mailsend.cmd will send mail to specified address.

    What I require is just enter those dates from text file instead of passing it to vbs file.
    One more can date be entered in the form of dd/mm/yyyy instead of yyyy/mm/dd.

  19. #19
    Registered User
    Join Date
    01-08-2014
    Location
    Chandigarh
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Passing Parameters t excel Macro

    Hi Richard,

    I got this http://stackoverflow.com/questions/2...d-with-cscript.
    Can you please check will it be helpful.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Passing Array's As Parameters
    By chuckury in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-26-2008, 10:08 AM
  2. Variable passing of parameters in a macro
    By gswhoop in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-05-2007, 03:25 AM
  3. passing parameters to dos from vba..
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-12-2006, 11:15 AM
  4. Passing Parameters to Word from Excel
    By jake1729 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-27-2005, 07:47 PM
  5. Passing parameters from excel to access
    By Jabeen in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-05-2005, 08:06 AM

Tags for this Thread

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