PDA

View Full Version : Request: VBA Code Convert to Word 2010



imshah
01-23-2013, 09:04 PM
Dear All,

My colleague was using the MACRO for fetching the photos for its quality control work. The VBA code is defined to simplify their work for enhancing the maximum possible productivity in less time ;)

But now as the company has upgraded to the latest version of Microsoft Office Word 2007 to Microsoft Office Word 2010. The code is not supported to the newer version or perhaps the coding framework not supporting.

I have also uploaded my screen shots for further clarification, if in case you need other info, please do let me know. But please expedite! :(

Following is the VB Code:

Dim pic(12), pictext(12)
Dim fotoname(1000) As String
Dim zahler, zahler2 As Integer
Dim strA
Private Sub Browse_Click()
Location.Hide
ChangeFileOpenDirectory ("C:\")
Set opendialog = Dialogs(wdDialogFileOpen)
opendialog.Display
Path.Text = CurDir
Location.Show
End Sub
Private Sub Cancel_Click()
End
End Sub
Private Sub OK_Click()
If OK.Value = False Then
Location.Hide
zahler2 = 1
strA = 1
Set fs = Application.FileSearch
With fs
.LookIn = Location.Path.Text
.FileName = "*.*"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
zahler = .FoundFiles.Count
Selection.PageSetup.TopMargin = InchesToPoints(0.13)
Selection.PageSetup.BottomMargin = InchesToPoints(0.25)
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.Font.Size = 14
Selection.Font.Bold = wdToggle
Selection.Font.Name = "Arial"
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2, NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior

With Selection.Tables(1)
.AllowAutoFit = False
End With

With Selection.Tables(1)
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
End With
Selection.Tables(1).Select
Selection.Rows.HeightRule = wdRowHeightExactly
Selection.Rows.Height = InchesToPoints(3.1)

Selection.TypeParagraph
For i = 1 To .FoundFiles.Count
fotoname(i) = .FoundFiles(i)
HelpText = Len(fotoname(i))
HelpText = Mid(fotoname(i), HelpText - 2, 3)
If HelpText = "JPG" Or HelpText = "jpg" Or HelpText = "bmp" Or HelpText = "tif" Then


Selection.InlineShapes.AddPicture FileName:=fotoname(i), _
LinkToFile:=False, SaveWithDocument:=True
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.InlineShapes(1).Fill.Visible = msoFalse
Selection.InlineShapes(1).Fill.Transparency = 0#
Selection.InlineShapes(1).Line.Weight = 0.75
Selection.InlineShapes(1).Line.Transparency = 0#
Selection.InlineShapes(1).Line.Visible = msoFalse
Selection.InlineShapes(1).LockAspectRatio = msoTrue
Selection.InlineShapes(1).Height = 180#
Selection.InlineShapes(1).Width = 239.75
Selection.InlineShapes(1).PictureFormat.Brightness = 0.5
Selection.InlineShapes(1).PictureFormat.Contrast = 0.5
Selection.InlineShapes(1).PictureFormat.ColorType = msoPictureAutomatic
Selection.InlineShapes(1).PictureFormat.CropLeft = 0#
Selection.InlineShapes(1).PictureFormat.CropRight = 0#
Selection.InlineShapes(1).PictureFormat.CropTop = 0#
Selection.InlineShapes(1).PictureFormat.CropBottom = 0#
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
Selection.Font.Size = 11
Selection.Font.Bold = wdToggle
Selection.TypeText Text:="Pict. "
Selection.TypeText Text:="0" + strA
Selection.HomeKey Unit:=wdLine
Selection.TypeText Text:=vbTab & " "
Selection.EndKey Unit:=wdLine
strA = strA + 1
Selection.TypeParagraph
Selection.MoveRight Unit:=wdCell
Selection.TypeParagraph

End If
Next i
End If
End With
End If
End Sub

macropod
01-29-2013, 12:58 AM
Your code uses Application.FileSearch, which is not supported by either Office 2007 or Office 2010. Accordingly, that part of your code will have to be re-written. See the discussion at: http://answers.microsoft.com/en-us/office/forum/office_2007-customize/dir-vs-filesearch/9021a162-7ec5-4c16-bff8-84f28300dba4. You can download the class file referred to there from: http://dl.dropbox.com/u/35239054/FileSearch.cls

PS: When posting code, please use the VBA button to apply formatting tags around it. They'll give your code a proper structure that makes it easier to read.

macropod
01-29-2013, 01:29 AM
Cross-posted at: http://www.excelforum.com/word-formatting-and-general/895223-help-request-vba-code-convert-to-word-2010-a.html
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

imshah
01-29-2013, 02:44 AM
Thanks for your sharing.

imshah
01-29-2013, 02:52 AM
Thanks macropod for your suggestion i will have a look on. If i will get the desired output than it will be great otherwise i have to bother you again.

I hope you will bear with me in.

Regards,

/imshah

arronlee
08-19-2013, 07:42 PM
Thanks for your nice sharing. But using code is too complicated for me to solve the related conversion work. As for me, I prefer to do with the WORD conversion work with some fine 3rd party tools whose way of processing is simple and fast. For example, I used to convert Word to image (http://www.yiigo.com/guides/csharp/how-to-convert-word-to-image.shtml) with the help of the free trial package of an image and document tool. It is just one of many but I do appreciate its simple way of processing. Even though I only tried its free trial package to convert Word and didn′t check the cost and licensing conditions, it worked great for me. Besides, this site also gives a lot of tutorials about how to convert document image using C#.NET (http://www.yiigo.com/guides/csharp/how-to-convert.shtml). Share with you. And I will try your sharing later. Thanks again.



Best regards,
Arron