Discussion Locked

Problem on VB 6.0 code

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,
I'm Dwij,inexperienced in VB 6.0 programming, i have been working on a code since long. the code runs as follows:-

Public Sub dn_formatreport()
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim Cible As Paragraph

dirige = App.Path
Set objfso = CreateObject("Scripting.FileSystemObject")
Set WordApp = CreateObject("Word.Application")
Set repertoire = objfso.GetFolder(dirige & "\Files")
WordApp.Visible = False
piedepage1 = "MCB Factors Ltd., MCB Centre, 9-15 Sir William Newton Street, Port Louis, Republic of Mauritius"
piedepage2 = "Company Number 57525, Telephone: (230) 202 5701, Fax: (230) 208 5082, email: mcb.factors@mcb.co.mu"
Form1.ProgressBar1.Value = 0
Form1.ProgressBar1.Max = repertoire.Files.Count
For Each element In repertoire.Files
Form1.ProgressBar1.Value = Form1.ProgressBar1.Value + 1
Set WordDoc = WordApp.Documents.Open(dirige & "\Files\" & element.Name)
With WordDoc.Sections(1)
.PageSetup.Orientation = wdOrientPortrait
.PageSetup.DifferentFirstPageHeaderFooter = False
.PageSetup.TopMargin = CentimetersToPoints(3.2)
.PageSetup.BottomMargin = CentimetersToPoints(2)
.PageSetup.LeftMargin = CentimetersToPoints(2.5)
.PageSetup.RightMargin = CentimetersToPoints(2.5)
.PageSetup.HeaderDistance = CentimetersToPoints(0)
.PageSetup.FooterDistance = CentimetersToPoints(0)
.Headers(wdHeaderFooterPrimary).Shapes.AddPicture FileName:=dirige & "\Images\logo.jpg", LinkToFile:=False, SaveWithDocument:=True, Left:=196, Width:=70, Height:=68
.Footers(wdHeaderFooterPrimary).Range.Text = piedepage1 & vbCr & piedepage2
.Footers(wdHeaderFooterPrimary).Range.Paragraphs.Alignment = wdAlignParagraphCenter
'.Footers(wdHeaderFooterPrimary).Range.Font.ColorIndex = Word.WdColorIndex.wdDarkRed
.Footers(wdHeaderFooterPrimary).Range.Font.Bold = True
.Footers(wdHeaderFooterPrimary).Range.Font.Size = 10
'.Footers(wdHeaderFooterPrimary).PageNumbers.Add
End With
For Each Cible In WordDoc.Paragraphs
Cible.Range.Select
If Trim(Cible.Range.Words(1)) = "Account" Then
Selection.MoveUp unit:=wdLine, Count:=1
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Selection.MoveLeft unit:=wdCharacter, Count:=1, Extend:=wdExtend
signedby = Trim(Selection.Text)
Selection.MoveUp unit:=wdLine, Count:=1
On Error Resume Next
Set objShape = Selection.InlineShapes.AddPicture(FileName:=dirige & "\Images\Signatures\" & signedby & ".jpg", LinkToFile:=False, SaveWithDocument:=True)
If Err.Number <> 0 Then
Set objShape = Selection.InlineShapes.AddPicture(FileName:=dirige & "\Images\Signatures\Sandra.jpg", LinkToFile:=False, SaveWithDocument:=True)
With objShape 'adapter l'index si d'autres images existantes dans le document
.LockAspectRatio = msoTrue
.Height = .Height * 0.85
.Width = .Width * 0.85
End With
Selection.MoveDown unit:=wdLine, Count:=1
Selection.MoveLeft unit:=wdCharacter, Count:=6
Selection.Text = "For "
Else
With objShape 'adapter l'index si d'autres images existantes dans le document
.LockAspectRatio = msoTrue
.Height = .Height * 0.85
.Width = .Width * 0.85
End With
End If
End If
Next

WordDoc.SaveAs FileName:=dirige & "\Files\" & element.Name, FileFormat:=wdFormatDocument
WordDoc.Close
Next
WordApp.Quit
Set WordApp = Nothing
End Sub

Hope someone could help me on this...

Cheers Dwij

5 replies

by amitdwij

Sorry,
Didnot even asked the question.....
VB is reading th ecode only to"If Trim(Cible.Range.Words(1)) = "Account" Then" then it stops. does not even save the Word doc created

by amitdwij

the code... will format a word document inserting a header and a footer and then insert a signature in the document at a certain point ..

the problem with the code is that it does not insert the signature which is stored in .JPEG format....

Please help me if possible as it very important for me.

by amitdwij

Please note that the problem has been solved...

Actually the problem was in the references in VB 6.0. I had activated Object library for both Excel And Word.. the Code that i created was VBA that was being run on VB 6.0 thus there was a conflict between word and excel.

Thanks for you help...
Hope this help others...

This discussion is closed to new replies.