General discussion


Problem on VB 6.0 code

By amitdwij ·
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:"
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
End With
For Each Cible In WordDoc.Paragraphs
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 "
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

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

Hope someone could help me on this...

Cheers Dwij

This conversation is currently closed to new comments.

5 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

dumb question but...

by Slayer_ In reply to Problem on VB 6.0 code

What exactly is your problem in this code?

Collapse -

My Mistake....

by amitdwij In reply to dumb question but...

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

Collapse -

This code is in a word document?

by Slayer_ In reply to My Mistake....

Can you describe what this code is supposed to do?

Collapse -

Trying to explain

by amitdwij In reply to This code is in a word do ...

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.

Collapse -

Problem Solved

by amitdwij In reply to Trying to explain

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...

Back to Software Forum
5 total posts (Page 1 of 1)  

Related Discussions

Related Forums