Macro needed to insert a file chosen from a directory

Can anyone help me please? I need a macro which allows me to insert text from 
whichever file I choose from a directory.

The idea is to click on a toolbar icon > display the folder containing the 
text files > select the text file > Click to insert file. The trouble is I 
could do it on my home PC but could not do it on my work network.

I used the macro from a previous post and it was great but I seem to have 
trouble with the insert part of the macro and it includes both the S: path 
and the C: temp path when asking me if I'm sure this is the file I want.

Macro used:
Sub MySpecFileInsert()
defPath = Options.DefaultFilePath(wdDocumentsPath)
Options.DefaultFilePath(wdDocumentsPath) = "S:\Insert"

Set myDialog = Dialogs(wdDialogInsertFile)

If myDialog.Display = -1 Then
    tempPath = Options.DefaultFilePath(wdDocumentsPath)
    If tempPath = "s:\insert" Then
        myDialog.Execute
    Else
        x = MsgBox("Are you sure you want to insert " & tempPath _
          & "\" & myDialog.Name, vbYesNo)
        If x = 6 Then
            myDialog.Execute
        End If
    End If
End If

Options.DefaultFilePath(wdDocumentsPath) = defPath
End Sub


Thanks!

0
Utf
6/3/2010 3:13:01 AM
word.vba.general 1023 articles. 1 followers. Follow

1 Replies
1288 Views

Similar Articles

[PageSpeed] 25

Try the following:

    Dim fd As FileDialog
    Dim FiletoInsert As String
    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .Title = "Select the File that you want to insert"
        .InitialFileName = "S:\Insert\*.doc*"
        .AllowMultiSelect = False
        If .Show = -1 Then
            FiletoInsert = .SelectedItems(1)
            X = MsgBox("Are you sure that you want to insert " & 
FiletoInsert & at the location of the selection?", vbYesNo + vbQuestion)
            If X = vbYes Then
                Selection.Range.InsertFile FiletoInsert
            End If
        End If
    End With
    Set fd = Nothing


-- 
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Marley" <Marley@discussions.microsoft.com> wrote in message 
news:02A859A5-351C-4BB7-8E2F-50BFEC91B9EF@microsoft.com...
> Can anyone help me please? I need a macro which allows me to insert text 
> from
> whichever file I choose from a directory.
>
> The idea is to click on a toolbar icon > display the folder containing the
> text files > select the text file > Click to insert file. The trouble is I
> could do it on my home PC but could not do it on my work network.
>
> I used the macro from a previous post and it was great but I seem to have
> trouble with the insert part of the macro and it includes both the S: path
> and the C: temp path when asking me if I'm sure this is the file I want.
>
> Macro used:
> Sub MySpecFileInsert()
> defPath = Options.DefaultFilePath(wdDocumentsPath)
> Options.DefaultFilePath(wdDocumentsPath) = "S:\Insert"
>
> Set myDialog = Dialogs(wdDialogInsertFile)
>
> If myDialog.Display = -1 Then
>    tempPath = Options.DefaultFilePath(wdDocumentsPath)
>    If tempPath = "s:\insert" Then
>        myDialog.Execute
>    Else
>        x = MsgBox("Are you sure you want to insert " & tempPath _
>          & "\" & myDialog.Name, vbYesNo)
>        If x = 6 Then
>            myDialog.Execute
>        End If
>    End If
> End If
>
> Options.DefaultFilePath(wdDocumentsPath) = defPath
> End Sub
>
>
> Thanks!
> 
0
Doug
6/3/2010 4:49:57 AM
Reply:

Similar Artilces:

How can I open a file saved in Pub 2000 version 6 in Pub 2000 ver.
The file is saved in Publisher 2000 v6 and I am trying to open it with Publisher 2000 v9. can this be done? Hi LaTrice (LaTrice @discussions.microsoft.com), in the newsgroups you posted: || The file is saved in Publisher 2000 v6 and I am trying to open it || with Publisher 2000 v9. can this be done? No. There is no such thing as Publisher 2000 v9, nor is there a version 9 of Publisher, yet. Verify the version of Publisher that you have, and also verify the version of Publisher that you received the file from then post back. -- Brian Kvalheim Microsoft Publisher MVP http://www.publi...

Hello i Need a good partner
Hello every one in the room i love you all, if you like to work with me join me on yahoo ID so that we can chat to know each other better...ericallen12007@yahoo.com -- ericallen http://forums.slipstick.com ericallen wrote: > Hello every one in the room i love you all You can't love someone that you don't even know exists. So you start out with a lie. > if you like to work with me You are also unknown since you haven't bothered to establish your identity based on a number of your posts over time in these newsgroups. You already started with a ...

Inserting charts into many workbooks
Hi, I'm using Excel 2007 and am pretty new to VBA. I have a folder with 40 or so workbooks- all with the same worksheet table format. The worksheets are huge (20 000 + rows, 50 or so columns). I need to open a workbook, make several fully formatted graphs, then insert the same graphs into every workbook , updated them with that workbooks' data. Any ideas on code for this? This isn't fully automated, but it will save some time. In one workbook, create the chart and format it to your specs. Then paste the chart into another workbook, and use the utility linked to i...

SBS 2008 Virtualization Question
Hi All, We have a volume license of SBS 2008 Premium...thus, I would like to install the Server 2008 license on a jacked up server, then activate Hyper-V so I can installed SBS 2008 virtualized. I am getting ready to order a Dell T610 with the following specs. Dual 2.13 Quad Core Processors 16 GB of RAM OS on RAID 1 (300 GB) DATA on RAID 5 (1 TB array) Redundant Power Supply Mainpine 2 port Fax board My questions are the following: 1) How does this hardware config look to all of you? Will this be enough? How much RAM should I allocated to the Server 2008 in Hyper - V r...

To write living will do I need special format
I just need to change and update a living trust You should consult someone with the appropriate legal knowledge in the jurisdiction in which you are domiciled. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP, originally posted via msnews.microsoft.com "belladonna" <belladonna@discussions.microsoft.com> wrote in message news:F25A64CB-355F-44E9-A005-16AA61DA15A7@microsoft.com... > I just need to change and update a living trust ...

Need help getting this code to compile under VS.NET 2003 (compiles under VS6.0).
I'm tasked with converting a LARGE project from VS6.0 to VS.NET 2003. Here is a VERY scaled down version of an error I'm getting. I must be getting rusty, but the way to get around this compiler error is just not coming to me. If you need to compile this, just create a Win32 console app and specify to add support for MFC, then copy this code into the cpp file and press compile. class CLogItem : public CObject { protected: virtual BOOL CheckConflict(CLogItem* pItem) const; }; struct MapEntry; //forward declaration.. typedef CArray<MapEntry, MapEntry&> CMapEntryArray;...

Insert an autofiltered range into another tab
I'm am having an issue when trying to insert a range from an autofilter on one sheet to another. The range has to be inserted above rows that have data in them. When I use the insert.shift:xldown, it only moves down the first column. TIA, Sub B_CreateTabs() Dim rngE As Range Dim lngLastRow As Long Dim mgrval, lobval, shtval As String mgrval = "myself" lobval = "dept" shtval = mgrval & "-" & lobval Windows("Mybook.xls").Activate Sheets(shtval).Select Sheets(shtval).Copy After:=Workbooks("Mybook.xls&quo...

automatically naming files for savingb
Hi, for delivery notes i would like excel to look in the relative directory for a given customer, ie if C4 contains superspecs, files relating to this account would be in c:\work\superspecs\ files are named superspecsdel0001,superspecsdel0002.......etc superspecsinv0001...etc for delivery notes and invoices. what i would like is a line (or more) to add to a macro which will look in the appropriate directory, add 1 to the last four digits of the last file, enter this number into a cell on the sheet and save the new file with the appropriate name, then close the file. is this possible, or alte...

why do changes only save locally on networked excel file?
why do changes only save locally on networked excel file? ...

How to get a macro to do what i want?
I have designed a form in Excel and the data that is inputted i want to be able to save in a separate worksheet. The problem i am having is that eveytime i record the macro, it over writes the same row each time (if that makes sense). For example if i copied every cell in the form and paste them into the database Row 1, i then want the new piece of information inputted into the form to go into Row 2 and then Row 3 etc.... But it keeps going into Row 1, it wouldnt move down the rows. Hopefully this makes sense to someone and someone can give me some advise. Calculate the last row ...

suggestion needed !!!!!!!!!!
In my company the want to calculate phone calls done by each sales person at the end of the day. Please give me suggestion how to implement this. Mahain, A quick solution would be 1) Create an advance find view based on the criteria you are looking for ie. Activity of the type phone call, Status = completed 2) Export the list to Excel (Dynamic pivot table/worksheet) 3) If pivot : Drag and drop relavent fields 3) If worksheet: filter by date and use sum. The advantage of dynamic excel report is it updates itself when ever you open the sheet. Hope this is helpful Venkat http://venkatbendalam...

Integration Manager need a registration key for test company?
Hi all, Can anyone tell if I need the registration key for IM if I am doing some testings on Test company (World Online)? Also, can I specify the company database in IM for the data to import to? Please advise. Thanks You do not need a reg key for the Two Company, and if you are using the standard adapter the data will integrate into the Company that is open in Great Plains. You can Specify which database you want to integrate into by using the SQL Optimizer. You do not need great Plains open for this adapter. "Terry" wrote: > Hi all, > > Can anyone tell if I nee...

Active Directory/Exchange problem
All, Before I joined my current employer the admin here upgraded from Exchange 5.5 to Exchange 2000(Box A) and then added another Exchange 2000 box to the organisation(Box B)and migrated the data in Box A to Box B. Box B is now the working exchange server and Box A is no longer used. The problem is that if I actually shut down Box A I can add a new user to Active Directory but I am unable to modify a users email/smtp details. All mail can still be transferred with no problems which would lead me to believe that Exchange is Ok but there is some sort of Active Directory link between the two bo...

Macro to apply alternate grey/white shading to selected paragraphs
Dear Experts: I would like to do paragraph shading using grey shading alternately. Example: this is a sample text This is another sample text This is yet another sample text This may be the last paragraph acquiring grey shading This is the penultimate paragraph This is the last paragraph With these 6 paragraphs selected, I would like to run a macro which applies grey shading alternately to the selected paragraphs, i.e. grey/ white (no shading) alternately. Help is much appreciated. Thank you very much in advance. Regards, Andreas Use Dim oRng As Range For i = 2 T...

Outlook should keep files in the clipboard after closing a window
When you open a message (in a new window) in Outlook 2007, and copy one or more files contained in this message, and then close the window, the file is not kept in the clipboard. I have to copy the file and paste it before closing the window. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I ...

Insert Static Date as part of Macro
I've built a nice macro, but I want it to insert the date it is run in an empty cell within the macro's range. When working within a spreadsheet, Ctrl +; returns the system date, but I can't figure out how to put that command into a macro. The macro recorder editor shows that the system recognizes the entry as the current date, not a function that returns the current date. The now() or today() functions are both dynamic ... they change with the system date. That's not acceptable in this situation. I need to seen when the macro was run. Thanks for any help, Ralph di...

Macro Security, Password Recovery & VB Code execution
I have found that if I set my macro security to high, VB code within (non-trusted) excel sheets do not execute... a microsoft security feature that ostensibly prevents non- trusted users from running VB The questions I have are : Is there a way to guarantee VB macro-execution using digital certificates or what-have-you ? Is there a way to detect, either within excel (well, not possible, it seems) or from outside, that the combo of users macro-security settings and signature status of a perticular excel file, WILL prevent VB from executing, if the file is attempted to opened ? ...

How to insert a URL with spaces into message body
Is it possible to insert a URL containing a space into a message body from a mailto hyperlink without using brackets? For example: <a href="mailto:jackblack@microsoft.com? body=<http://www.micro% 20soft.com>">jackblack@microsoft.com</a> This link will insert the URL '<http://www.micro soft.com>' (with a space between the 'o' and the 's') into the message body. However, the brackets will be visable too. If I remove the brackets, only the 'http://www.micro' portion will be hyperlinked. The 'soft.com' portion wi...

Deleted file in Outlook
I accidentaly deleted a folder in Outlook 2003 and am wondering if it possible to retreive it. Thank you, Karl youthminman@yahoo.com <youthminman@yahoo.com> wrote: > I accidentaly deleted a folder in Outlook 2003 and am wondering if it > possible to retreive it. Unless you permanently deleted it (i.e., held down Shift when pressing Delete), it will be in your Deleted items folder, unless you've emptied that folder. If you have emptied it, other suggestions depend on knowing what data store you're using (PST or Exchange mailbox). -- Brian Tillman ...

Can't insert rows
I am using Excel 2007 and have just loaded a spreadsheet created in a previous version which is running in Compatibility mode. When I try to insert a row I get an message "Cannot shift objects off sheet". How do I insert rows on this sheet? No problem with another workbook loaded at the same time which was created in 2007. See if this helps http://support.microsoft.com/default.aspx?kbid=211769 "Cannot shift objects off sheet" error message when you hide columns in Excel -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my...

Import directory data into Excel 2003
I have over 1000 media files that I would like to extract information from and put into an Excel spreadsheet. Using Explorer, I have defined the fields I would like to see, such as title, duration, comment etc. Now, I need to import this data into Excel. So far, I've not been able to find a way to do this. Can someone offer some suggestions please? Thanks, Nigel -- www.myoldcontacts.com - Tell your friends to tell their friends www.sysadmininc.com - Consultancy, Service, Sales, Networking... www.british-expats.com - Connect with British Expats World Wide www.kxez.com/shows_britishinv...

Macros and Active X
My ctrl+c and ctrl+v shortcuts dont work unless I turn on my active forms bar to edit mode. Any guesses why -- Message posted from http://www.ExcelForum.com Because the spreadhseet is "live". You have to go into edit mode t make any changes to control toolbox items. -- Message posted from http://www.ExcelForum.com I'm not trying to edit my active x forms, The problems is that th standard ctrl+c and ctrl+v copy and paste short cuts wont work unles the active x edit mode is turned on. I don't have to turn on the active x edit mode to use these short cut in other wo...

Find Replace with Macro
Can anyone tell me how to construct a macro that will seacrh the entire contents of column C, find the contacts of cell A1 and replace it with B1, then do the same finding A2 and replacing it with B2 in column C, then A3 with B3 in column C etc etc. I can not get this to work. Sub Test() Dim r1 as Range Dim r2 as Range For Each r1 in Range("A1:A" & Range("A65536").End(xlUp).Row For Each r2 in Range("C1:C" & Range("C65536").End(xlUp).Row If r1.Value = r2.Value Then r2.Value = Range("B" & r1.Row).Value Next Next End Sub -...

help needed on multiple option buttons
Hi, I am trying to use option buttons in a few different locations in Excel. In one cell i want three options and three different buttons. In another locations, two options with their own two buttons. However, the 5 buttons act as 5 linked options, so i can only have one or another button selected at a time. I would like one of the first three selected and one of the next two and so on. Can anybody help me work out how to resolve this. Thanks, If you used optionbuttons from the Forms toolbar, put a nice groupbox (also from the forms toolbar) around each group. If you use optionbuttons ...

Inserting dashes to an existing number
Hi, I am trying to create a formula that will divide this ten digit numbe into the following dashes. Here is the number 1234000999 I need the dashes to be inserted in thi format 1234-000-999. What is the appropriate formula. Thanks for your help. Dinahros -- dinahros ----------------------------------------------------------------------- dinahrose's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=1334 View this thread: http://www.excelforum.com/showthread.php?threadid=26643 Why not just custom format right click on selection>format>number>custom...