How to open a xls file with Excel in VB - vb.net

So, how can I tell the system to open the file for me? I've tried
Shell(ExcelFilePath)
But an exception was thrown although the file path is from OpenFileDialog.FileOk
So, I am trying to play with Excel.Application, is it possible to open the file with that?

This will open the file with Excel:
Process.Start("EXCEL.EXE", """C:\Folder\file.xls""")
Being the second string the arguments for the process. See the MSDN Dcoumentation.

try this
System.Diagnostics.Process.Start("FilePath")
it will open the file in an application associated with it.

Related

Writing to an online .txt file without opening the file

Hi I'm trying to create some sort of log system in an excel add-in im working on and so far the best way I can think of doing this is to collect event text together and then when excel attempts to close append this text to an online text file hosted on a team sharepoint. Not everyone will have the drive mapped locally so I want to ideally do this through the file URL and also not open the file as im adding the text.
So far I've managed to do this with a local file but cannot figure out how to do this with an online file through a URL. Here is what I have so far:
Sub testThis1(control As IRibbonControl)
Dim strFile_Path As String
strFile_Path = "C:/***" '<=a real address goes in here
Open strFile_Path For Append As #1
Write #1, "This Is my sample Text" & Now
Close #1
How can I go about taking this approach on a web hosted file rather than a local file? Thanks in advance for any help!

Error while trying to open .xls files

I have some information in a .xls file (I downloaded it from SAP) and I need to paste it in a .xlsm file.
I'm trying to open that file like always but I have the following error:
Run-time error ‘-2147221080 (800401a8)’:
The file format and extension of ‘file.xls’ don’t match. The file could be corrupted or unsafe. Unless you trust its source, don’t open it. Do you want to open it anyway?
and two options: End and Debug. If I choose debug, I get the following error:
Run-time error ‘-2147221080 (800401a8)’: Automation error
I couldn't find anything in Google. How can I fix it? It's impossible to have the information in another format that is not .xls
Maybe try to open the file with notepad? Notepad can open almost any file. It could be that the content will show strange characters though.

Make my applescript process specified files in the current directory?

I need to generate PDFs from word files regularly, and I'm getting tired of doing it by hand.
Manually, all I do is open a file, and click "Save as PDF". So, one would think applescript would be a nice easy way to do this. [If you have another approach than applescript, I'm open to it.]
I'm almost there, the following script works, except the full path is hard coded.
tell application "Microsoft Word"
open file "Macintosh HD:Users:me:repos:training:class:Activities:ActivityGuide.docx"
set doc to document "ActivityGuide.docx"
save as doc file name "Macintosh HD:Users:me:repos:training:class:Activities:ActivityGuide.pdf" file format format PDF
end tell
I need it to work for other people, on other machines, so the username and other parts of the path may change. If I could just do this from the current directory for the script, I'd be set.
I found this: Applescript to launch file from current folder?
tell application "Finder"
open file "somefile.txt" of folder of (file (path to me))
end tell
Which works for opening an app from the current directory in Word, via Finder, but I think I need to open it with an application of "Microsoft Word", if I'm going to use "Save As". But this method of opening doesn't work if I change the application for "Finder" to "Microsoft Word".
Any suggestions welcome.
[edit: clarity]
Try this
set x to path to me
tell application "Finder" to set tFile to (file "ActivityGuide.docx" of (container of x)) as alias
set newFile to (text 1 thru -5 of (tFile as string)) & "pdf"
tell application "Microsoft Word"
open tFile
tell document 1
save as file name newFile file format format PDF
close saving no
end tell
end tell
Another thing that might be helpful to you is under System Preferences:Keyboard:Shortcuts: App Shortcuts:All Applications
Make a shortcut that is named "Save as PDF..." assign the shortcut to command+P since most applications that is the shortcut for print, then just press it twice and it will prompt you to save it as a PDF (I got that tip from David Sparks) and depending on the application it will default to where the file was opened up from. You can also set that with the application Default Folder X.
Hopefully that is a bit more of a global solution for other problems but it looks like you already have the answer to this isolated problem.

Photoshop Scripting with Applescript -- will not open images without a prompt

tell application "Adobe Photoshop CS5.1"
set myFile to (choose file) as string
open file myFile
end tell
This results in 2 separate dialogs opening asking me what file to open.... It doesn't matter what I select first, it asks a second time and opens the second.
What I want to open is a PDF, so I really want:
tell application "Adobe Photoshop CS5.1"
set myFile to (choose file) as string
open file myFile as PDF with options {class:PDF open options, mode:CMYK, resolution:300, use antialias:true, page:1} showing dialogs never
end tell
Result:
Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop
All right a more direct approach:
tell application "Adobe Photoshop CS5.1"
set myFilePath to alias "other: PREPRESS SAVE:GAMES:3Sudoku:20120213pzsud-v:sudoku 0213.pdf"
with timeout of 300 seconds
open myFilePath as PDF with options {class:PDF open options, mode:CMYK, resolution:300, use antialias:true, page:1}
end timeout
end tell
The file exists or the setting of the alias would fail. So what do I get?
"Error: -43. Adobe Photoshop CS5.1 got an error: File some object wasn’t found."
I had asked over on the Adobe forums, with no response. The full code I'm really trying to use is there if you're interested. I reduced it to basics to figure out what the problem is.
Is there a setting somewhere that I am missing? I'm not sure what is wrong, the example out of the
There are horrible issues with The Photoshop 5 dictionary. One idea is to try and run it in 32-bit mode which 'solves' a lot of issues. Please digest further in http://forums.adobe.com/message/2822670#2822670?tstart=0#2822670
Might be a CS5 issue, but I honestly don't know.
This worked fine for me, but with CS4:
tell application "Adobe Photoshop CS4"
set myFile to (choose file) as alias
with timeout of 300 seconds
open myFile as PDF with options {class:PDF open options, mode:CMYK, resolution:300, use antialias:true, page:1}
end timeout
end tell
The only real difference (that I can see) is that I alias the chosen file, and call open ... - not open file ...

Opening a file in my application from File Explorer

I've created my own application in VB.NET that saves its documents into a file with it's own custom extension (.eds).
Assuming that I've properly associated the file extension with my application, how do I actually handle the processing of the selected file within my application when I double click on the file in File Explorer?
Do I grab an argsc/argsv variable in my Application.Load() method or is it something else?
Try this article but short answer is My.Application.CommandLineArgs