Solved

Can you pass parameters to a vb program???

Posted on 1998-10-01
3
168 Views
Last Modified: 2010-04-30
Is it possible to pass parameters to a vb program from DOS? Like, can you do the following:

program test1.psd newtest.psd

where program is the exe, test1.psd is the original file, and newtest.psd is the new file created by the program.

Also, is it possible to create a vb program that does not have a GUI?

P.S. Sorry about the lack of points. I've used them all up.
0
Comment
Question by:hobster
3 Comments
 
LVL 1

Expert Comment

by:abhinavm
ID: 1437714
yes you can pass parameters to vb programs. you can use Global variable 'Command' which contains the command line parameters passed to your program.
  Answer of second question is also yes, you can have VB program without GUI. write your code in standard modlue and make Sub Main as startuo in project properties. You have to write a procedure main which will be called first when you run the app. from main you can call other functions
0
 
LVL 2

Author Comment

by:hobster
ID: 1437715
Your second answer is correct.

Can you provide more details for the first answer? Below is some simple code that opens an Excel file and saves it to a different name. How would I change the code so I can do the following from the command prompt:

program test.xls newtest.xls

Thank you.

Option Explicit

Sub Main()
   Run
End Sub

Private Sub Run()
   
   Dim xlApp As Object
   Dim spreadsheet As Object  
   
   Set xlApp = CreateObject("excel.Application")
   Set spreadsheet = CreateObject("Excel.Sheet")
   
   spreadsheet.Application.Visible = True
   
   Set spreadsheet = xlApp.OpenAs("N:\temp\ole\test.xls")
   spreadsheet.SaveAs "N:\temp\ole\newtest.xls"
     
   spreadsheet.Application.Quit
     
   spreadsheet.Close
             
   xlApp.Quit
   
End Sub

0
 
LVL 1

Accepted Solution

by:
ylarvor earned 0 total points
ID: 1437716
Option Explicit

Dim cmd As String
Dim nb_car As Integer
Dim begin_nam, end_nam As String

Sub main()
   cmd = Command()
   nb_car = InStr(cmd, ".xls")
   nb_car = nb_car + 4
   begin_nam = Trim$(Left(cmd, nb_car))
   end_nam = Trim$(Mid(cmd, nb_car))

   Run
End Sub

Private Sub Run()
   
   Dim xlApp As Object
   Dim spreadsheet As Object    
     
   Set xlApp = CreateObject("excel.Application")
   Set spreadsheet = CreateObject("Excel.Sheet")
   
   spreadsheet.Application.Visible = True
     
   Set spreadsheet = xlApp.OpenAs("N:\temp\ole\" & begin_nam)
   spreadsheet.SaveAs "N:\temp\ole\" & end_nam
       
   spreadsheet.Application.Quit
       
   spreadsheet.Close
               
   xlApp.Quit
   
End Sub
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA/SQL - Connect to SQL server and pull data 4 88
Using "ScreenUpdating" 6 55
Access Object Property from VBA Module in Excel 2010 2 27
How to Add / Edit Windows Menu 4 51
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now