Very simple routine will not run?

andy54

New Member
Joined
Jun 22, 2008
Messages
4
I am just starting out with VBA 2005 and have written (copied) a routine from the "VB2005 in 24 Hrs" book, which will not run. The code is (I'm sure) written correctly but when the code tries to show the file dialog box (on clicking the SelectPicture" button), I get an error dialog box saying ""INVALIDOPERATIONEXCEPTION WAS UNHANDLED File<make empty> is not a valid name".
The code is listed below..... Can anyone see what I've done wrong?

Andy

Public Class frmViewer
Private Sub btnSelectPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectPicture.Click
'Show the open file dialogue box.
If ofdSelectPicture.ShowDialog = DialogResult.OK Then
'Load the Picture into the Picture box.
picShowPicture.Image = Image.FromFile(ofdSelectPicture.FileName)
'Show the name of the file in the form's caption.
Me.Text = "Picture Viewer(" & ofdSelectPicture.FileName & ")"
End If
End Sub
Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click
'Close the window and exit the application
Me.Close()
End Sub
End
Class
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Hi

VB and VBA are different beasts - if you're plonking that code in a standard module in a workbook it ain't gonna work.
 
Upvote 0
Hi,
The routine is for VB and is compiled using VB 2005 (as per the VB2005 in 24 hours book). It just doesn't want to run. Can you tell from the code what I've done wrong?
 
Upvote 0
Andy

This is an Excel help board - I'm afraid I, personally, no nothing about VB.Net. Your best bet (if nobody else offers up a solution) would be to target a VB.Net forum.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top