• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Word VBA

chirayu

Well-Known Member
Hi All,

Wanted to know which site is good to ask Word VBA related questions. As far as I know this forum is Excel only right?
 
The only thing I know about Word VBA is that it exists! Would be a good idea to have forums for these apps as well on Chandoo.

On VBAX, the word forum was active sometime back and there were couple of Word MVPs always around. Macropod (Paul Edstein) was one. I don't go there as frequently as I did in the past (and it was always Excel VBA and not word VBA) but you can check out.
www.vbaexpress.com

The other one was MSDN forums. I had posted there couple of times as in case of word VBA there's no start point. I could not find any recommended VBA books on it as well.

Hope this helps somewhat.
 
Thanks. I'm basically trying to create a Loop based code that matches the name of the file with images in a folder. If name matches then it will add a sheet and insert image in sheet. If it doesn't match then it should move on to next file in folder. I read a lot online and came up with the below but loop code not working.

Code:
'Links Used by Chirayu Walawalkar:
'http://stackoverflow.com/questions/11564857/how-do-i-get-the-current-filename-of-a-word-document-without-the-extension-or-f
'http://word.tips.net/T000819_Determining_if_a_File_Exists.html
'http://word.tips.net/T001437_Batch_Template_Changes.html
 
Function FileThere(FileName As String) As Boolean
  FileThere = (Dir(FileName) > "")
End Function
 
'===
 
Sub Case_Image()
 
'loop to work on all files
Dim strDocPath As String
Dim strCurDoc As String
Dim docCurDoc As Document
strDocPath = "C:\Cases\" '>>>>> change folder path if cases stored in different folder
strCurDoc = Dir(strDocPath & "*.doc") '>>>>> check if doc or docx and change accordingly
Do While strCurDoc <> ""
Set docCurDoc = Documents.Open(FileName:=strDocPath & strCurDoc)
 
'get my document name without .doc/.docx and other extensions
Dim doc As String
If InStrRev(ActiveDocument.Name, ".") <> 0 Then
  doc = Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1)
Else
  doc = ActiveDocument
End If
 
'check if my image exists and matches my document name
'if image found then add new page and copy image
If FileThere(ActiveDocument.Path & "\images\" & doc & ".jpg") Then '>>>>> relates to the function written above
Selection.InsertNewPage
Selection.InlineShapes.AddPicture FileName:= _
ActiveDocument.Path & "\images\" & doc & ".jpg", _
LinkToFile:=False, SaveWithDocument:=True
 
'if image not found then give me a message saying that
Else
'''''MsgBox "Image not found", vbInformation, ""
End If
'=====
docCurDoc.Close wdSaveChanges
' get next file name
strCurDoc = Dir
Loop
MsgBox "Folder consolidated", vbInformation, ""
End Sub
 
Back
Top