Jump to content

seekaye

Member
  • Posts

    2
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    United Kingdom

About seekaye

seekaye's Achievements

0

Reputation

  1. many thanks for your suggestions i 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 START Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'USER SELECTS A FILE AND STORES IT IN FILE Dim file As String file = "" OpenFileDialog1.FileName = "" If OpenFileDialog1.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then file = OpenFileDialog1.FileName End If 'STORE ALL THE FILES IN THE SAME DIRECTORY IN A NEW ARRAY CALLED FILE Dim files() As String = System.IO.Directory.GetFiles(GetDir(file), _ "*.*", IO.SearchOption.TopDirectoryOnly) Dim a As Integer 'OPENS UP A NEW WORD DOCUMENT Dim objWord As New word.application objWord.Visible = True objWord.Documents.Add() 'FOR EVERY FILE IN THE files ARRAY CREATES A HYPERLINK IN THE WORD DOC For a = 0 To UBound(files) objWord.Selection.Hyperlinks.Add(Anchor:=objWord.Selection.Range, _ Address:=files(a), _ SubAddress:="", _ ScreenTip:="", TextToDisplay:=GetFile(files(a)) + Chr(13)) Next End Sub 'RETURNS THE PATH OF THE DIRECTORY OF A GIVEN FILE Function GetDir(ByVal file) GetDir = "" Dim a, last As Integer For a = 1 To Len(file) If Mid(file, a, 1) = "\" Then last = a Next For a = 1 To last - 1 GetDir = GetDir + Mid(file, a, 1) Next MsgBox(GetDir) End Function 'RETURNS THE FILE NAME GIVEN THE ENTIRE PATH Function GetFile(ByVal file) GetFile = "" Dim a As Integer For a = 1 To Len(file) If Mid(file, a, 1) = "\" Then GetFile = "" Else GetFile = GetFile + Mid(file, a, 1) End If Next End Function End Class 'CODE ENDS
  2. I have a directory with 50 or so word/excel files in i'd like to create a hyperlink for each one in word e.g. if the first file was MyFile.doc the first line on my word doc would be MyFile.doc (or even better jusy MyFile Is this possible? it takes ages to do each one indiviudally can anyone write me a macro? thanks
×
×
  • Create New...