Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Launch An Excel File From Vb Application


  • Please log in to reply
8 replies to this topic

#1 Guest_WelshSteve_*

Guest_WelshSteve_*

  • Guests
  • OFFLINE
  •  

Posted 08 March 2007 - 04:52 AM

I have just downloaded and installed Visual Basic 2005 Express Edition. I want to create a simple application that has buttons on the main form. When a button is clicked, I want it to open an excel spreadsheet. Then from within the spreadsheet, to have a button to close the spreadsheet, which will then return the app.

Anyone know how I can do this?

BC AdBot (Login to Remove)

 


m

#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD

Posted 08 March 2007 - 08:19 AM

What do you mean you want it to return to the application; you mean you want the workbook to close when you push a button?

This should help with going the other way.

#3 Keithuk

Keithuk

  • Members
  • 951 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:01:40 PM

Posted 08 March 2007 - 08:25 AM

I don't use .NET but the priciple is the same in VB6. Use the ShellExecute API.

Const SW_SHOW = 5

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()

ShellExecute Me.hwnd, "open", "c:\yourexcel.xls", vbNullString, vbNullString, SW_SHOW
Thats assuming you have Office installed on your comp. :thumbsup:

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#4 Guest_WelshSteve_*

Guest_WelshSteve_*

  • Guests
  • OFFLINE
  •  

Posted 08 March 2007 - 08:41 AM

What do you mean you want it to return to the application; you mean you want the workbook to close when you push a button?

This should help with going the other way.


Sorry that doesn't help at all. None of the examples I have found on the internet work in the 2005 Express Edition. I'm following the tutorials I find exactly, but I keep getting errors. Even with Microsoft tutorials.

Edited by WelshSteve, 08 March 2007 - 08:42 AM.


#5 Guest_WelshSteve_*

Guest_WelshSteve_*

  • Guests
  • OFFLINE
  •  

Posted 08 March 2007 - 08:42 AM

I don't use .NET but the priciple is the same in VB6. Use the ShellExecute API.

Const SW_SHOW = 5

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Sub Command1_Click()

ShellExecute Me.hwnd, "open", "c:\yourexcel.xls", vbNullString, vbNullString, SW_SHOW
Thats assuming you have Office installed on your comp. :thumbsup:


Where do I put that? In the click event of a command button?

#6 Keithuk

Keithuk

  • Members
  • 951 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:07:40 PM

Posted 08 March 2007 - 04:08 PM

Where do I put that? In the click event of a command button?

Yes Private Sub Command1_Click() is a default Command button in VB6. I'm not sure of the layout of .Net but the other code goes at the top of the code window or in a Module. :thumbsup:

Keith

Windows ME (spare computer)
Windows XP 2002 Professional SP3 (desktop computer)
Windows 7 Professional SP1 32bit (laptop computer)

Windows 8 64bit spare drive for laptop computer


#7 Guest_WelshSteve_*

Guest_WelshSteve_*

  • Guests
  • OFFLINE
  •  

Posted 09 March 2007 - 04:10 AM

Sorry everyone, but none of this has worked so far.

Why is it so difficult to find resources on the net for this? I would have though that as VB and Excel are both Microsoft products, the process would be simple and seamless.

Then again, we are talking about Microsoft here.

#8 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD

Posted 09 March 2007 - 01:05 PM

Perhaps instead of being critical of Microsoft and the various resources on the 'net, we could see some code. It is difficult to diagnose what is wrong without that. It has been my experience that nearly every time I find resources on the web that they work, once I understand what I am doing. You are not just going to be able to drop it into your code and have it work, and we have no way of knowing what other things might be going on in your code that could potentially cause conflicts. :thumbsup:

#9 Guest_WelshSteve_*

Guest_WelshSteve_*

  • Guests
  • OFFLINE
  •  

Posted 12 March 2007 - 05:05 AM

Hi groovicus.

I don't have any code at the moment, apart from the suggestions made above. There is no other code I want. Just some code I can put in a click event for a command button that will launch an excel file. The application I want to build doesn't have anything else in it. :thumbsup:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users