seekaye Posted July 26, 2007 Share Posted July 26, 2007 I have a directory with 50 or so word/excel files ini'd like to create a hyperlink for each one in worde.g. if the first file was MyFile.docthe first line on my word doc would be MyFile.doc (or even better jusy MyFileIs this possible? it takes ages to do each one indiviudallycan anyone write me a macro?thanks Link to comment Share on other sites More sharing options...
TravisO Posted July 26, 2007 Share Posted July 26, 2007 I'm sure there's a magic macro out there, but being a web dev, I'd try this (it might not even work as I'm sure Word links are very different than HTML links but it's worth a shot).Find some classic ASP code (I have some but not on me) that looks at the folder and generates HTML links. Since classic ASP is usually VBScript, you can easily modify it to run in DOS and pipe it out to a .HTML file. View the file in your web browser, then copy and paste the text Link to comment Share on other sites More sharing options...
IcemanND Posted July 26, 2007 Share Posted July 26, 2007 in firefox type in the path to the folder you want the list made from.It will list all of the folders and directories in a hyperlink. Copy and paste the page into word.You need to reformat it to your desired look and to remove date and time stamps. Link to comment Share on other sites More sharing options...
seekaye Posted July 26, 2007 Author Share Posted July 26, 2007 many thanks for your suggestionsi moved away from macros and into VB express and came up with this solution (eventually..)i'd never interacted with word from VB express before i tried this.[microsoft word 11.0 object library needs added to COM references]'CODE STARTPublic Class Form1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load'USER SELECTS A FILE AND STORES IT IN FILEDim file As Stringfile = ""OpenFileDialog1.FileName = ""If OpenFileDialog1.ShowDialog() <> Windows.Forms.DialogResult.Cancel Thenfile = OpenFileDialog1.FileNameEnd If'STORE ALL THE FILES IN THE SAME DIRECTORY IN A NEW ARRAY CALLED FILEDim files() As String = System.IO.Directory.GetFiles(GetDir(file), _"*.*", IO.SearchOption.TopDirectoryOnly)Dim a As Integer'OPENS UP A NEW WORD DOCUMENTDim objWord As New word.applicationobjWord.Visible = TrueobjWord.Documents.Add()'FOR EVERY FILE IN THE files ARRAY CREATES A HYPERLINK IN THE WORD DOCFor a = 0 To UBound(files)objWord.Selection.Hyperlinks.Add(Anchor:=objWord.Selection.Range, _Address:=files(a), _SubAddress:="", _ScreenTip:="", TextToDisplay:=GetFile(files(a)) + Chr(13))NextEnd Sub'RETURNS THE PATH OF THE DIRECTORY OF A GIVEN FILEFunction GetDir(ByVal file)GetDir = ""Dim a, last As IntegerFor a = 1 To Len(file)If Mid(file, a, 1) = "\" Then last = aNextFor a = 1 To last - 1GetDir = GetDir + Mid(file, a, 1)NextMsgBox(GetDir)End Function'RETURNS THE FILE NAME GIVEN THE ENTIRE PATHFunction GetFile(ByVal file)GetFile = ""Dim a As IntegerFor a = 1 To Len(file)If Mid(file, a, 1) = "\" ThenGetFile = ""ElseGetFile = GetFile + Mid(file, a, 1)End IfNextEnd FunctionEnd Class'CODE ENDS Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now