+ Reply to Thread
Results 1 to 19 of 19

Passing Parameters t excel Macro

Hybrid View

  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.

    .Run "FolderTraverse", cLng(DateSerial(2014,3,12))
    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
    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.

  8. #8
    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

  9. #9
    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

  10. #10
    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.

  11. #11
    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

  12. #12
    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.

  13. #13
    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.

+ 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. [SOLVED] 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. [SOLVED] 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