LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Macro to Insert Object with browsing ability

Hello all,

I have, unfortunately, entered the realm of VBA limbo, where I
understand how code works by reading it, but have no idea how to write
it (having just picked things up over time).

What I am trying to do is add functionality into my workbook where a
user can click a button to insert an object, much like you would do
via the Insert -- Object menu option.

My current thought was to use Jim Rech's 'Browse for Folder' in
combination with a simple recorded Macro. Basically, the user should
click the button, be prompted with an ability to select the file to
insert, and then have that location of the file be returned back to
the VBA code so that it can go ahead and insert it.

I can work the macro's independently - Jim's will browse for a file,
but only returns a msgbox. My simple recorded macro will insert an
object fine, but only from a static - hardcoded filename. I'd
obviously like to replace the embedded filename with the prompting
from Jim's code so that rather than return a msgbox, it returns the
filename to my own macro and voila, object inserted.

If there is a better method I am very open to it.

Thanks!

Jim's BrowseForFolder (minus all the background info obviously):

Sub BrowseFolders()
Dim RetStr As String, Flags As Long, DoCenter As Boolean
Flags = BIF_RETURNONLYFSDIRS + BIF_BROWSEINCLUDEFILES +
BIF_NEWDIALOGSTYLE
With Sheet1
DoCenter = True
End With
RetStr = GetDirectory(CurDir, Flags, DoCenter, "Please select a
location to store data files")
If RetStr < "" Then MsgBox RetStr
End Sub

My easy recorded Macro, would like to replace the "c:\...." with what
comes from Jim's, but can't figure it out:

Sub InsertObject()
ActiveSheet.OLEObjects.Add(Filename:= _
"c:\files\file.abc", Link:=True, _
DisplayAsIcon:=True, IconFileName:= _
"C:\WINDOWS\Installer
\{90110409-6000-11D3-8CFE-0150048383C9}\xlicons.exe", _
IconIndex:=0, IconLabel:= _
"c:\files\file.abc").Select
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
turn on insert comments ability in Excel dave parta Excel Discussion (Misc queries) 2 April 11th 08 10:47 PM
Macro to insert a object in excel Lester from AUS[_2_] Excel Discussion (Misc queries) 5 March 28th 07 02:47 AM
Macro to insert object into spreadsheet ?? kluska Excel Programming 1 August 18th 06 09:19 PM
Browsing/opening a file with a macro Chip Smith Excel Discussion (Misc queries) 1 April 5th 06 12:56 AM
Excel needs to have the ability to insert "SUB" worksheets KFEagle Excel Worksheet Functions 2 July 27th 05 08:13 PM


All times are GMT +1. The time now is 09:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"