issue with macro that fill a word document with text

kerm007

Active Member
Joined
Mar 16, 2019
Messages
266
Office Version
  1. 365
Platform
  1. Windows
hello
we have an excel sheet that contain a macro who create a word document
every time we running it it fill all line with "all tests" even if the line 7 is empty.
not sure why.
plus the word doc created put text sometime in 2 lines instead of 1


here the code :
VBA Code:
Sub Main()

  StartForm.Show
 
  Dim Name As String
  Dim OwordDocument As WordDocument
  Dim OoutlookEvents As OutlookEvents
  Dim Item As String
  Dim Items() As String
  Dim element As Variant
 
  Sheet1.Activate
 
  Dim LastCol As Integer
    With ActiveSheet
        LastCol = .Cells(2, .Columns.Count).End(xlToLeft).Column
    End With

  If ActiveSheet.Cells(StartForm.LineTextBox, 1).Text <> "" Then
 
      Name = ActiveSheet.Cells(StartForm.LineTextBox, 1).Text
      
      Set OwordDocument = New WordDocument
      Set OoutlookEvents = New OutlookEvents

      OwordDocument.InsertTitle (Name)
      
      For i = 2 To LastCol
      
        If ActiveSheet.Cells(StartForm.LineTextBox, i).Text <> "" And i <> 30 Then
        
          Item = ActiveSheet.Cells(3, i).Text + " " + _
            ActiveSheet.Cells(2, i).Text + " " + ActiveSheet.Cells(4, i).Text + " " + _
            ActiveSheet.Cells(StartForm.LineTextBox, i).Text + ActiveSheet.Cells(5, i).Text + " " + _
            ActiveSheet.Cells(6, i).Text + ActiveSheet.Cells(7, i).Text + _
             " ,all tests"
              
          OwordDocument.InsertItem (Item)
          OoutlookEvents.SetEvent (Item)
        
        End If
      
      Next
      
      If ActiveSheet.Cells(StartForm.LineTextBox, 30).Text <> "" Then
        
        Items = Split(ActiveSheet.Cells(StartForm.LineTextBox, 30).Text, Chr(10))
        
        OwordDocument.InsertRetests
            
        For Each element In Items

            OwordDocument.InsertItem (element)
            OoutlookEvents.SetEvent ("Retest: " + element)
        
        Next element
        
      End If
 
  End If
 
End Sub





Thanks
 

Attachments

  • all tests.png
    all tests.png
    29.2 KB · Views: 18

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I think Word has an InsertBefore, InsertAfter and InsertCaption, but no inserttitle, insertitem or insertretests.... is this AI code? You also don't seem to have a Word application running? Does this code actually compile and output anything? To insert text in a document you can just use TypeText "whatever" at the selection. HTH. Dave
 
Upvote 0
they run the macro and it create a word document the issue is at some place it mark all tests not sure why
 
Upvote 0
its not ai code it was someone that did it long time ago who is not here anymore
Thanks
 
Upvote 0
I think Word has an InsertBefore, InsertAfter and InsertCaption, but no inserttitle, insertitem or insertretests.... is this AI code? You also don't seem to have a Word application running? Does this code actually compile and output anything? To insert text in a document you can just use TypeText "whatever" at the selection. HTH. Dave
do you have other ideas ?
Thanks
 
Upvote 0
To begin with, 257 posts, so you must be familiar with all forums cross posting guidelines? I'm guessing the reason(s) for not resolving this are: firstly, from your description, it's impossible for anyone else to understand what your final objective is and what the actual problem is; secondly, the code has a bunch of stuff that makes no sense. Google VBA inserttitle, VBA insertitem, and VBA insertretests... as I mentioned before, there are no such terms. So if this code actually does anything, which it really doesn't seem like it does, there must be some Form initialization and/or activation code that runs and/or some nifty class module code that does something.... either way you haven't provided it. I would suggest reviewing the forum guidelines for whatever forums this has been posted to, pick a forum and present your overall objective and desired outcome, provide a copy of your wb and start a new. HTH. Dave
 
Upvote 0
OK
i will tries to speak to the guy that create this at first since he's no longer with us
basically they run the excel and it create a word document and the word document produce get line market all test wich was not suppose to
i will check if i can provide you with the files they use
Thanks
 
Upvote 0

Forum statistics

Threads
1,223,880
Messages
6,175,153
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top