Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Visual Basic





See Related Forum Messages: Follow the Links Below to View Complete Thread

Using Shell Command To Open Csv File In Excel
I am using the shell command to open a csv file in excel from a button in a VB6 program of the type:
retval = Shell(path+"excel.exe filename.csv", vbNormalFocus)
this works OK, but if I open another csv file by the same method a second copy of excel is used.

I want to open the second csv file as a new workbook in the same copy of excel as the first csv file. How is this done ?

thanks for any help

Shell + Open File
Hi!

I have made a simple executable file in VB whose only purpose is to start another application using the shell command, but I think I need some help from someone more experienced than me to make it do what I want.

My executable VB file uses code like this:
Program=Shell (“C:Program FilesProgA.exe” , vbnormalfocus)

It works great to start the A.exe by double-clicking my VB executable file (B.exe), but what I also want to accomplish is to make it possible to double-click a filetype that is associated with B.exe, and have it start up A.exe and also open the file inside it. With my recent code it starts up A.exe, but it doesn’t automatically open the file. Can this be done somehow?

I have changed the filetype normally associated with program A.exe to point to B.exe instead. Like this: C:ProgramMyAppB.exe “%1”
I can understand if you wonder why I’m doing something stupid like this, but please don’t ask. I have my reasons.

Open A File Shell Extension?
hi there

is it possible to write a shell extension to fire some code if a .msg file is opened?

cheers

Jamie

Open Txt File As Read-only Using Shell...
Hi all,
I have a text file that consists of instructions and general help info to an app I wrote. I am using Shell and notepad to open this file. Since a user couls possibly edit this file once opened as is, is there a switch or parameter in Shell that would open this file as READ-ONLY?

If not, any quick easy suggestions? I don't want to spend a whole lotta time on it. Just something to get the job done...

Thanks a ton...

Start App And Open File With Shell()
OK, I have my code written so far to open a file with its associated .exe using:


Code:
Shell ExePathAndFilename & " " & FilePathAndFilename, vbMaximizedFocus


but its not working. I believe that the reason is because I am passing the file's path and name as the full Windows path and filename (C:WindowsMyDocument.doc) and it is expecting it in DOS short filename format (C:WINDOWSMYDOCU~1.DOC).
So what I would like to find out:

1) Is there a way to convert the long filename to its DOS equivilant?

or

2) Is there a way to use the long filename in Shell() that I am missing?

or would there be a totally different issue that may be causing my problem?


Thanks

Using Shell To Open Notepad With A File
Yo yo yo

I want to use shell to open notepad and then open a file within notepad
the only thing that I have is


Code:
Shell ("Notepad")


now I need to somehow use my app to open a file in notepad

any Ideas?? (Im using vb6)

How To Open A Particular Topic Of Chm File Using Shell
hi
i create a chm file in third party tool and call it by using shell in VB project. Now tell me how can i open a particular topic of chm file when i press F1 at any particular form of VB project.

thanks

lyba



Edited by - lyba on 10/16/2005 8:42:06 PM

SHELL Open Folder + Focus On The File
hi guys..

i have this line of code here on my cmdOpenFolder


Code:
Shell "explorer.exe " & GetDirName(txtAFileLocation), vbNormalFocus
what i would like to happen is to open the folder containing the file, and that windows explorer would focus on the file.

thank you.

Shell Default Application To Open A File
how do you shell a document instead of an application so that it opens with the default application for openiong files of that filetype. Basically what i a trying to do is shell a word document so it loads word or wordperfect. I cant be arsed to mess about with the registry anymore.

Open Excel And Make It Open A Text File
Hey, friends,

I need to open excel, make it open a comma delimited text file, format it, and after that, end my application leaving the user in excel... i am starting as follows but at that point, excel does not appear, why? (it seems to work but i can not see excel)

Quote:





Dim XlApp As Excel.Application
Set XlApp = New Excel.Application
XlApp.DisplayFullScreen = True






Thanks for your help!

Heyner

Shell An Excel (.xls) File
I want to open a .xls file from within VB6, but I dont want to have to create any objects to do so.

In order to do this i would have to do something like:

x = Shell("Excel.exe c: est.xls")

This obviously doesn't work since I need full path information to Excel.exe. Is there a better way than querying the registry for the InstallRoot?

Ex. "SoftwareMicrosoftOffice9.0ExcelInstallRoot"

This would be necessary assuming office can be installed an a drive other than C.

Thx in advance.

Exporting An Access Table To A New Excel SS And Open Excel File Afetr Export
Hi,

Can some help me with writing the code to Export a table from Acces into a new excel spreadsheet, then open an instance of excel to view the newly exported table? I can get the file to export but I am having trouble with the code to open Excel, thanks for you help. See code below..

Private Sub Command26_Click()

DoCmd.TransferSpreadsheet transfertype:=acExport, _
        tablename:="newreqtable", _
        FileName:="F:UserdataSelectionData.xls", hasfieldnames:=True, _
        Spreadsheettype:=8
        
MsgBox "Export is Complete", vbOKOnly, "Selection Data Export"

MsgBox "Your new file is located on F:UserdataSelectionData.xls", vbOKOnly, "Data Export Location"

'This is where I need to have excel open the file for the client.

End Sub

Open Excel File (into Microsoft Excel)
2 main questions:

1.
I want to open (with Microsoft Excel) an Excel file from a Visual Basic program. Lets say in the Visual Basic program, if I click on the command button "Open It", Microsoft Excel loads up and then opens the file.

--Basically what I have so far--
Dim FileName As String

Private Sub OpenIt_Click()
'What goes here?
End Sub
--End of Basically what I have so far--

2.
After loading the file, I want a Macro to run immediately after the file loads up.

--Basically what I have so far--
'Magical On-load Function()
'On-load Macro
'End Magical On-load Function
--End of Basically what I have so far--

1 Bonus question:
Can macros outside of Microsoft Excel be used on Excel files? Is this question complete rubbish?

Any help is smiled upon .

Open Excel File W/out Opening Excel Itself
Is it possible to open an Excel file for reading data without having to open the Excel app? I would like to do this to save overhead but have not ran across any methods to accomplish this task.

All help is appreciated.

Thanks.

Excel File Created In VB Won't Open In Excel
I have created a file in VB that writes numbers and formulas etc into an excel file. If I do not set the visible property of the file to false, I can see all the data successfully going into Excel. I can retrieve the results of a formula I have written into a cell. When I save the file from VB, it is totally unuseable when I open it in Excel. Can you shed some light on what I need to do to make the file available from Excel? Thanks.

Excel - On A Button Event, Open Another Closed File, Post Changes, Close File
Really new to VBA but coming along.

I hope that this hasn't been addressed already in this forum, I looked but didn't find it ...

The issue I can't resolve is this: I have a shared workbook with multiple sheets, essentially counting instances of answers from lists (lots of 'em) across all sheets. These are being summed in my 'summary' sheet (countif). Upon a button event (available on each sheet), I am posting from the summary to the summary2 sheet ... using the following:

Sub GetAns()
Sheets("Summary2").Select
Range("D5").Select
Selection.Offset(0, 0) = Application.Sum(Sheets("Summary").Range("D5").Value, Sheets("Summary2").Range("D5").Value)
Selection.Offset(1, 0) = Application.Sum(Sheets("Summary").Range("D6").Value, Sheets("Summary2").Range("D6").Value)
.+
.+

Long story, but I have Summary (current tally) and Summary2 (total tally)

The thought is this - this book is to be shared by 50+ users who will update it periodically yet constantly. What I would like to accomplish, essentially, would be to to have 'summary2' as an external closed book that accepts the posting from each save from the open books 'summary' sheet ... using vba (ActiveWorkbook.Save) in my GetAns sub ... basically 'on save, add this value to that value in that book' ... 'that' book will be a running tally of all users answers ...

Sorry, I hope this makes sense ... Can anyone help ?

Make A Backup Copy Of Excel File, While The Particular File Is Open Through A Macro
I am working on excel file ABC.xls. While the file is still open I want to run a macro which will make a copy of the current ABC.xls as Backup ABC.xls and save it in the same folder and then I can continue to work on ABC.xls. I tried following code for a macro, but it did not work. I ran the macro from ABC.xls. I am going to use it in an excel based application that I am developing.
Sub Macro1()
'

Dim Filename

Dim Dest

Dest = "E:My DocumentsBackupABC.xls"

Filename = "E:My DocumentsABC.xls"

FileCopy Filename, Dest
End Sub
Please guide me.

Excel - Selecting A File Using Windows File Open Window
Hi,

I am working in an Excel Sheet(Say from Excelfile1.xls ). How should I select another Excel file(say from Excelfile2.xls) from someother folder in my machine? Can the Windows 'File Open' Window(or File Chooser window) can be displayed on click of a button in an Excel Sheet? If yes, How?

Thanks in advance,
Nikhil

 

Edited by - kulksnikhil on 5/3/2003 3:47:09 AM

Shell To Open Specific File From Specific Program
shell can open MS Word like so:

MyAppID = Shell("C:WORDWINWORD.EXE", 1)

But I want to open a specific file.

How?

Thanx in advance.

Rami

Keeping DOS Window Open After Using SHELL To Open It
Currently, I have made a program with an about box made in QBASIC (DOS) as an executable, and have linked it to a command button in my VB project.


Code:
Private Sub Command1_Click ()
Shell "Aboutme.exe /k", 1
End Sub

The DOS program runs correctly, but is it possible to keep the DOS command window open after the program execution? I would like to do this because all the credits are displayed after the execution of the program. And for everyone who is wondering why I don't use VB to do the the About box, it's because I can't do the animation required in VB. Also, I am using Windows XP. Thanks for anyone that can help.

Shell Couldn't Open And Open Nothing Problem
I used this:
id is a variant

id = Shell("start C:My Documents o CD ext.txt", vbNormalNoFocus)

ran the VB program and MS-Dos prompt window opens and closes without openning the text.txt. I used exactly the same thing (start C:My Documents o CD ext.txt) and it opens!

So I added the quotes:
id = Shell("""start C:My Documents o CD ext.txt""", vbNormalNoFocus)
ran the VB program and now there's an error: runtime error "53":
file not found

The file is there! Why could VB just open it? Please assist

Open Excel File
Hi All,

I have been trying to find a code snippet for opening and using an excel file that already exists. I read through the great tutorial on using excel, but only allows me to write to and save a new excel file. I would like to read cells from am existing file. That is, open an existing file reading it's cell values, updatng some of them, then closing it and saving changes. The code I am presently using just fine is:


Code:
Dim oExcel As Excel.Application
Dim oWB As Excel.Workbook
Dim oWS As Excel.Worksheet

Set oExcel = New Excel.Application
oExcel.Visible = True ' <-- *** Optional ***

Dim oRng1 As Excel.Range
Dim oRng2 As Excel.Range

Set oWB = oExcel.Workbooks.Add
Set oWS = oWB.Worksheets("Sheet1")

Set oRng1 = oWS.Range("A1")
oRng1.Value = "Hello World"
Set oRng2 = oWS.Range("B2:E5")
Call oRng1.Copy(Destination:=oRng2)

oWB.SaveAs (FileName) ' <-- Results saved here.

Cleanup:
Set oWS = Nothing
If Not oWB Is Nothing Then oWB.Close
Set oWB = Nothing
oExcel.Quit
Set oExcel = Nothing

Thanks for any help.

Can I Open An Excel File On A Mac?
I have a Windows Excel file that I want to share with a number of users, some of them are PC users and some are Mac users. The Mac users are unable to open my file. The problem seems to be the VBA script and macros.

Is there an emulator out there that will enable them to open and use my Excel file successfully?

Open Excel File If Not In Use
i am trying to write a procedure which allows a user to open a file , if this file is not already opened by another user. I used Createfile API with sharing set to 0 but it didn't work.

Open SECOND Excel File....
Hi all!
Simple question:

What do I have to do to open a SECOND excel file?
---
Dim xlap As New excel.Application 'Opens 1 excel appl.

sub open_excelfile()
xlap.Workbooks.Open "C:file1.xcl" 'Open's 1st excel file
end sub

sub close_excelfile()
xlap.Workbooks.Close
xlap.Quit
Set xlap = Nothing
end sub

sub select_ragne()
xlap.Range("A1:A6").Select
end sub
---

If I declare a new object like:

Dim xlap_second As New excel.Application

it will start a new Excel, just for this second file
and this is a waste of memory.

Is it possible to open a NEW WORKBOOK?
I've seen that the property "Workbooks" has an index.
But I havent figured out how it works.

Thanks for any help!
Stay cool.

Open Excel File With VBA?
Hi everyone?

I'm trying to open a excel file trough autocad VBA.

my question is: can i open a excel file the same way as VB6?, or i will have to use some API, because i can´t make a reference to excel object library in the autocad VBA.


Thanks.

Open .csv File In Excel
Hi all,

I am trying to write a line of code to open an already existing .csv file using MS Excel. I thought it would just be a simple Shell command but that doesn't work as I expected. Here is the code that I am using


VB Code:
'Create and fill a .csv file with data    Dim exportPath As String        exportPath = "C:PayrollExportFile.csv"        Dim fso, txtfile        Set fso = CreateObject("Scripting.FileSystemObject")    Set txtfile = fso.CreateTextFile(exportPath, True)         txtfile.WriteLine "Company,Port Number,Payroll Week,Payroll Year,Work Date,Cargo Type,Terminal,Vessel,Job Number,Dispatch Number"        txtfile.WriteLine Me.lblCompany.Caption & "," & Me.lblPort.Caption & "," & Me.lblPayrollWeek.Caption & "," & Me.lblPayrollYear.Caption & "," & Me.lblWorkDate.Caption & "," & Me.lblCargo.Caption & "," & Me.lblTermPier.Caption & "," & Me.lblVessel.Caption & "," & Me.lblJobNum.Caption & "," & Me.lblDispatchNum.Caption      txtfile.Close   'open the recently created .csv file with Excel.    Shell "C:PayrollExportFile.csv" 'doesn't work...any ideas?  

Open Excel File In VB
OK, i have this excel file, it's position is d: emp.xls

I need to open the first sheet (sheet1) and put the first row in a list box... how do i do this?

Add/Open Excel File Using VBA
I have just started using VB in Excel to improve my spreadsheets but am having problems already. Hope someone can help.

In order to save data from the active workbook to another workbook my Save button opens an Input box asking for the project name (which is/will become the file name the data is to be stored in). This I have done. But then I need to check if the file exists in which case to open it else create a new workbook and name it as per the Input box.

Below is my feeble start;

' Remember where you were!
Dim currentworkbook As String
Dim currentpath As String
currentworkbook = ActiveWorkbook.Name
currentpath = ActiveWorkbook.Path

' Open Project Workbook
Dim ProjectFileName As String
ProjectFileName = Application.InputBox("Enter a Project File name to save joint design information to", "Save As", "Project1")

How To Open An Excel File From Vb ??
hi,

i want to display a previously saved excel sheet on the click of a button.

can u give me the code....

tx,

rajesh

Best Way To Open A Excel File?
Which is the best way to open a excelfile in VB? Is this the right way?


Function OpenXL()

Dim stAppName As String

stAppName = "excel.exe C:datamyexcel.xls"
Call Shell(stAppName, 1)

End Function

Open File In Excel
Hi Everyone,

How do you open a specific file in excel from VB using a click procedure. I have already set a reference to the Excel library. Any help would be appreicated. Thank you.

Open File In Excel
When opening a file in Excel I use this
Workbooks.open.filename:=_ "C:dirdirfree.xls". DOes anyone know how to have this name look at an actual cell address on a common page???

Can't Open Excel File In VB
HI
i'm facing a problem whenever i try to open the excel file

i used the code from the MSDN articale
i used the excel part ...

Every time i run the program i get the following error :


Code:


An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsApplication1.exe

Additional information: Old format or invalid type library.




here is my code ..
i just want the program to open the file .. that's all
i'm using VB .Net

Code:


Dim oExcel As Excel.ApplicationClass
Dim oBook As Excel.WorkbookClass
Dim oBooks As Excel.Workbooks

'Start Excel and open the workbook.
oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oBooks = oExcel.Workbooks
oBook = oBooks.Open("C:Book1.xls")



Can someone help me with this

Open Excel File With ASP
Hello to all,

1. How to open excel file using Active Server Pages (ASP)?
2. How to input value to specific row/column and sheet?

For ex.

I have a excel file (test.xls)
Then I want to open this.
After I opened it . I want to input testfile value to B4.

Please help



Thanks
Joseph

Open Excel File From VB
Hi mates,

I am trying to open an excel file from my VB 6.0 application.

I have used a filelistbox control, so that my users can see the files that
are present in a folder. I am trying to develop a code wherein my users can
just double-click on the files mentioned in the filelistbox and the Excel
file would get opened. Further, I would also like the Excel file to be
opened as read-only.



I am using Visual Basic 6.0 and Microsoft Office XP.



Can anyone please help me through this ....



Thanking you in advance







Best Regards,

Ratnajit C Vichare

I.T.Dept.,

Raymond Limited

How To Open An Excel File In VB
Hi

Can someone tell me how to open an excel file with a visual basic program? I have a boton in my form which should open an excel file called c:Plants.xls. I tried to use the shell funtion but it only executes .EXE file.
Thanks

Open Excel File
I am new to VB6 and need some quick help.  Well I hope this isn't to hard to do.  All I need the program to do is open an excel file I already have on my desktop.  I have a program already that opens a new excel file every time, but I don't need that.  Also if possible I would like it to start on sheet 2 instead of sheet 1.  I'll post the code I have.  Please tell me if it has to be redone in order for this to work. Thank you.

Option Explicit
'Variables for Excel
'Microsoft Excel 9.0 Object Library
Dim exlApp As Excel.Application
Dim exlWSheet As Object
Dim exlRow As Integer
Dim exlCol As Integer
Dim strExcelPath As String

Private Sub Form_Load()

'Start Excel and open new spreadsheet
Set exlApp = New Excel.Application
exlApp.Workbooks.Add
Set exlWSheet = exlApp.Workbooks(2).Worksheets(1)
exlApp.Visible = True
exlRow = 1
exlCol = 1

End Sub

Open Excel File Using Vb6
I need to open an excel file with a file name containing spaces, below is the code im using but it only opens file names without spaces
i am using an msflexgrid to list files then populating the path and file name into the variable inPath

Dim InPath As String
    
           'EXECUTE FILE USING ASSOCIATED APPLICATION
        InPath = Me.fgFiles.TextMatrix(Me.fgFiles.Row, 1) & Me.fgFiles.TextMatrix(Me.fgFiles.Row, O)
    (Me.fgFiles.Row, O)
           
    Dim X
    'TRY OPEN EXCEL UNDER NORMAL PATH
    X = Shell("C:MICROSOFT OFFICEOFFICEexcel.exe " & InPath, vbMaximizedFocus)
    
thanks in advance for any help i can get with this
    

Can't Open An Excel File Twice
Here's my code :
Code:
Option Explicit
Dim WithEvents xlBook2 As Excel.Application

Private Sub Command1_Click()
    
'Open Excel and File
    On Error Resume Next
    Set xlBook2 = GetObject(App.Path & "" & "Test.xls", "Excel.Application")
    If Err.Number <> 0 Then 'if excel is not running
        Set xlBook2 = CreateObject("Excel.Application")
        xlBook2.Workbooks.Open App.Path & "" & "Test.xls"
    End If
    
    xlBook2.WindowState = xlMaximized
    xlBook2.Application.Visible = True
    xlBook2.Sheets("Sheet1").Select
    
'Grey Cells
    xlBook2.Application.Range("B1:B4").Select
    With Selection.Interior
        .ColorIndex = 15
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
    End With
    
'Display Print Preview
    xlBook2.Worksheets.PrintPreview True
    
'Close Application
    xlBook2.Windows(1).Close False
    'xlBook2.Workbooks.Close savechanges:=False
    xlBook2.Application.Quit
    Set xlBook2 = Nothing
End Sub

I'm trying to open an excel file, grey some cells in it, get the print preview, then close the file without saving.
When I first press Command1, everything works fine. When I click again, then it does'nt grey the cell.

I'm using Microsoft Excel 9.0 Object Library.
I've try lots of stuff to make it works. Thing is Excel is still runnin in alt-ctrl-del.
I can't figure out how to write to that excel workbook twice without closing my visual basic application.

Can someone help me out pls? Thx

Open A New Excel File While Another Is In Use
I am using a Excel addin which works from one xls file the addin mean time generates
another xls file which is opened in new Excel window i want to make the new file as
the active window but the built in property ActiveWindow does not works for me
please help

Open Excel File From VB
Hi guys,
            How do i work with Excel sheets from within VB.
i.e ,I want to Open a Excel Sheet from and Write into it some data.Also need to Change the Properties of the cells in the Sheets.
Thanx in Advance,




VSK

Open A Pdf File With "Shell"
Hi: I have already written to consult for the following problem:
I have to do a book in whic I must open several files in pdf format by clicking a label for each file and they appear in full screen. I have the files in the folder "pdffiles". I´ve tried whit the following code

Dim RetVal
RetVal = Shell("C:AdobeAcrobat 4.0AcrobatAcrobat.exe C:PdffilesMetabolic alkalosis.pdf", 1)

but it didn´t work, but if I use the following code

Dim RetVal
RetVal = Shell("C:AdobeAcrobat 4.0AcrobatAcrobat.exe", 1)

the Acrobat Reader easily starts

Hack has already helped me (That was very kind of you Hack!!) whit "ShellExecute" but I couldn´t do it of that way

How can I do to open a pdf file just clicking a label?

Thank you for helping me again

Help: Open An Excel File To A Flexgrid
Is there any way to open an excel file to a flexgrid?
I dun know where to start out with. Pls help!

How Can I Open An Excel File From A Database?
Hello,

I'm looking for a manner to open an excel file from a database.

Have some code that does an output of a query to an Excel sheet but I also want to open automaticly another workbook?

Can somebody get me started with this one?

Regards

Open And Print File In Excel
I am very new to Visual Basic and I have come across a problem.
My boss at work wants me to be able to open and existing excel file, print it (various worksheets and print ranges), and then close it using a VB Macro.

If this isn't to hard to code will someone please help a new programmer.

Thanks

Checking If An Excel File Is Open
I got the following piece of code to check if an excel file is open from this forum, but it somehow always sets the return boolean value to true even if the file is not open..I'm accessing this excel file throughout my application to read in data.. but dont actually OPEN it, could that be the reason??? any idea why this code is failing???

code:
* this is where I check *
dim xlfileopen as boolean
xlfileopen = WorkbookIsOpen("c:Visual BasicAppraise v Develop economic model Version 2.0.XLS")
'xlfileopen = isFileOpen(frmdcfwiz2.Textpath.Text)
If xlfileopen = True Then
MsgBox "Close the Excel workbook while running the application", vbOKOnly, "Close Excel"
Exit Sub
End If

* this is my function*
Public Function WorkbookIsOpen(wbname) As Boolean
' Returns TRUE if the workbook is open
Dim x As Workbook
On Error Resume Next
Set x = Workbooks(wbname)
If Err = 0 Then WorkbookIsOpen = True _
Else WorkbookIsOpen = False
End Function


thanks
Madhuri78

Open First Excel File In Directory
Hi

I have created an Excel VBA macro looks in a directory and finds any files with the ".xls" extension. This is working fine, but now I want to open the first file that is found and perform some modifications. I cannot hardcode a file name because the names are constantly changing. I guess my question is there a way to assign a number variable to file names? If so, how, if not, is there another way? My code is below.

Code:
Sub OpenMyFiles()
Set fs = Application.FileSearch
With fs
.LookIn = "C:WINDOWSDESKTOP est"
.FileName = "*.xls"
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
Does anyone have any ideas?

Thanks

Open A Excel File From VB, Using Browse?
Can anyone tell me how to get Visual basic to open a file using the "Browse for.." method that is used for everything else in windows??

i.e. a user defined file, not one specified in the VB code.

Copyright © 2005-08 www.BigResource.com, All rights reserved