issue with excel macro

kerm007

Active Member
Joined
Mar 16, 2019
Messages
250
Office Version
  1. 365
Platform
  1. Windows
hello in our compagny we have an excel that [roce a word document plus entry in the outlook
some one came to me cause they enter line 250 it steems to not filling all line
here the macro : not sure why it's not working :(
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
 
  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 255
     
        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
 
hello is it good like that ?
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 !
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
It looks fine, but I am viewing on a mobile phone.
ok i add it after :
Sheet1.Activate

Dim LastCol As Integer
With ActiveSheet
LastCol = .Cells(2, .Columns.Count).End(xlToLeft).Column
End With


and replace 255 with lastcol

Thanks
 
Upvote 0

Forum statistics

Threads
1,214,611
Messages
6,120,513
Members
448,967
Latest member
screechyboy79

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