Creating Word documents from excel table - excel

I am trying to create word documents based on an excel table as follows:
At the end this creates 3 documents and each one has only the lines with Yes corresponding to it. My problem is that it doesn't keep the formatting of the lines. Can somebody help me with this? Here is the code:
Sub NewWordDocument()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Dim j As Integer
Dim LineCount As Integer
Dim DocumentCount As Integer
LineCount = Application.CountA(Range("A:A")) ' To see how many lines should be inputed
DocumentCount = Application.CountA(Range("B2:AZ2")) 'To see how many documents should be created
For j = 1 To DocumentCount
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add ' or 'Set wrdDoc =wrdApp.Documents.Open("C:\Foldername\Filename.doc") 'sample word operations
wrdApp.Selection.TypeText Text:="Heading One"
With wrdDoc
For i = 1 To LineCount
If Cells(i + 2, j + 1).Value = "Yes" Then
.Range.InsertAfter Cells(i + 2, 1) 'Different way to paste the text. It doesn't keep the formatting
.Range.InsertParagraphAfter
End If
Next i
If Dir("D:\" & Cells(2, j + 1).Value & ".docx") <> "" Then
Kill "D:\" & Cells(2, j + 1).Value & ".docx"
End If
.SaveAs ("D:\" & Cells(2, j + 1).Value & ".docx")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
Next j
End Sub
If I do it manually, copying the cell and pasting it in word works perfectly - keeps the format and removes the table but when I use 'Selection.PasteExcelTable False, False, False' instead of 'InsertAfter' , I simply overwrite the same text instead of adding to the end of the page.
Also, how can I format the "Heading one" to be bold and center?

I figured it out - it is probably not the best way to do it but it more or less works for me.
Sub NewWordDocument()
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim i As Integer
Dim j As Integer
Dim LineCount As Integer
Dim DocumentCount As Integer
LineCount = Application.CountA(Range("A:A")) ' To see how many lines should be inputed
DocumentCount = Application.CountA(Range("B2:AZ2")) 'To see how many documents should be created
For j = 1 To DocumentCount
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add ' or 'Set wrdDoc = wrdApp.Documents.Open("C:\Foldername\Filename.doc") 'sample word operations
wrdApp.Selection.Font.Name = "Calibri"
wrdApp.Selection.Font.Size = 18
wrdApp.Selection.Font.Allcaps = True
wrdApp.Selection.Font.Bold = True
wrdApp.Selection.TypeText Text:="Title"
With wrdDoc
.Sections(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add _
PageNumberAlignment:=wdAlignPageNumberRight, _
FirstPage:=True
.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "Header text" 'Add text in the header
.Content.InsertParagraphAfter
For i = 1 To LineCount
If Cells(i + 2, j + 1).Value = "Yes" Then
Range("A" & i + 2).Copy
wrdApp.Selection.GoTo What:=wdGoToBookmark, Name:="\Page"
wrdApp.Selection.MoveRight Unit:=wdCharacter, Count:=1
wrdApp.Selection.PasteSpecial
.Content.InsertParagraphAfter
End If
Next i
wrdApp.Selection.Font.Name = "Calibri"
wrdApp.Selection.Font.Size = 11
wrdApp.Selection.Font.Allcaps = False
wrdApp.Selection.Font.Bold = False
wrdApp.Selection.TypeText Text:="Ending Text"
If Dir("D:\" & Cells(2, j + 1).Value & ".docx") <> "" Then
Kill "D:\" & Cells(2, j + 1).Value & ".docx"
End If
.SaveAs ("D:\" & Cells(2, j + 1).Value & ".docx")
.Close ' close the document
End With
wrdApp.Quit ' close the Word application
Set wrdDoc = Nothing
Set wrdApp = Nothing
Next j
End Sub

Related

Exiting Word Table after pasting from Excel

I'm trying to copy information from an excel sheet to a new word document. Currently everything copies correctly on the first loop, but pastes into the previously pasted table in the next loop. I've tried every variation of ways to exit the table I can find through searching and none seem to fix the issue. Hoping someone can help.
Sub createWord()
Dim objWord
Dim objDoc
Dim heading As New DataObject
Dim fileName As String
Dim tableRange As Word.Range
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add()
fileName = ActiveWorkbook.Name
fileName = Left$(fileName, InStrRev(fileName, ".") - 1) & " Data.doc"
'objDoc.SaveAs fileName:=ThisWorkbook.Path & "\" & fileName
objWord.Visible = True
For i = 4 To Application.Sheets.Count
Dim k As Integer
k = ((i - 4) * 4) + 1
heading.SetText ThisWorkbook.Worksheets(i).Cells(1, 4).Value
heading.PutInClipboard
objDoc.Paragraphs.Add
objDoc.Paragraphs(k).Range.Paste
k = k + 1
Call copyGraphAuto(i)
objDoc.Paragraphs.Add
objDoc.Paragraphs(k).Range.Paste
k = k + 1
heading.SetText ThisWorkbook.Worksheets(i).Cells(24, 5).Value
heading.PutInClipboard
objDoc.Paragraphs.Add
objDoc.Paragraphs(k).Range.Paste
k = k + 1
Call copyTableAuto(i)
objDoc.Paragraphs.Add
objDoc.Paragraphs(k).Range.Paste
Set tableRange = objDoc.Tables(k - 3).Range
tableRange.Collapse Direction:=wdCollapseEnd
'Exit For
Next i
End Sub
Sub copyTableAuto(Optional ByVal sheetNumber As Integer)
Dim ppmCount As Integer
If sheetNumber = 0 Then sheetNumber = ThisWorkbook.ActiveSheet.Index
ppmCount = Worksheets(sheetNumber).Range("M4:M9").Cells.SpecialCells(xlCellTypeConstants).Count
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Worksheets(sheetNumber).Range("E29:E" & CStr(ppmCount + 28)).Merge
Worksheets(sheetNumber).Range("E25:I" & CStr(ppmCount + 28)).Copy
End Sub
Thanks
The issue is caused by your attempt to maintain an index of the paragraphs in the document.
As you are adding data to the document consecutively it would be better, and simpler, to use Word's own index and work with:
objDoc.Paragraphs.Last.Range

How to paste values on every page of word document from Excel VBA?

I have a long list of word-paths and start- and endtags in Excel. I need to open the word document using the path specified in Excel, and paste a start-tag on the beginning of every page, and an end-tag on every end of a page. Every document has three pages.
I'm struggling with Excel VBA and cant seem to get it to work. Can anyone help me?
I need my code to run through the list, opening the file, copy the starttag on the beginning of each page, and the end tag on the end of each page, save and close the document and go on to the next document.
My excel structure
Until now, I managed to open my excel document
Sub startword()
Set WordApp = CreateObject("word.Application")
Path = Range("B2").Value & Range("F5").Value
WordApp.Documents.Open Path
WordApp.Visible = True
End Sub
And I was able to copy and paste values to a NEW document.
Sub copyrange()
'declare word vars
Dim WrdApp As Word.Application
Dim WrdDoc As Word.Document
'Path = Range("B2").Value & Range("F5").Value
'declare excel vars
Dim ExcRng As Range
'create new word instance
Set WrdApp = New Word.Application
WrdApp.Visible = True
WrdApp.Activate
Set WrdDoc = WrdApp.Documents.Add
'create reference to range i want to copy
Set ExcRng = ActiveSheet.Range("B2:E6")
'copy the range and wait for a bit
ExcRng.Copy
Application.Wait Now() + #12:00:01 AM#
'paste the object in word
WrdDoc.Paragraphs(1).Range.PasteExcelTable LinkedToExcel:=True, WordFormatting:=True, RTF:=False
WrdApp.Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext
WrdDoc.Paragraphs(1).Range.PasteSpecial Link:=True, DataType:=wdPasteOLEObject
'clear clipboard
Application.CutCopyMode = False
End Sub
The range is totally random
PART TWO OF THE QUESTION
I'm struggling with the next piece of my code. I need to extract the contents between the first start and end tag (with the tag included) and move them to doc 1, same with page 2 to doc2, page 3 to doc 3. So I'll get three documents. doc1 with all the first pages of my documents, doc 2 with all the 2nd pages etc. I've made an attempt to find/select the code, but it selects the first and the last page, not the first one.
This is my current code for opening the word docs one by one:
Sub SelectRangeBetween()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1") 'Change to the correct sheetname
Dim wrdApp As Word.Application
Dim WrdDoc As Word.Document
Set wrdApp = New Word.Application '
wrdApp.Visible = True 'set to false for higher speed
Const StarttagColumn = "C" 'Edit this for the column of the starttag.
Const EndtagColumn = "D" 'Edit this for the column of the endtag.
Const FilelocationColumn = "E" 'Edit this for the column of the Filelocation.
Const startRow As Long = 5 'This is the first row of tags and filenames
'Const endRow As Long = 140 'uncomment if you want a fixed amount of rows (for ranges with empty cells)
Dim endRow As Long 'comment out if const-endrow is used
endRow = ws.Range("B" & Rows.Count).End(xlUp).Row 'comment out if const-endrow is used
Dim i As Long
For i = startRow To endRow
Dim wrdPath As String
wrdPath = ws.Cells(i, FilelocationColumn).Value2 '
If wrdPath <> vbNullString Then '
If Dir(wrdPath) <> vbNullString Then '
Dim startTag As String '
Dim endTag As String '
startTag = ws.Cells(i, StarttagColumn).Value2 '
endTag = ws.Cells(i, EndtagColumn).Value2 '
Set WrdDoc = wrdApp.Documents.Open(wrdPath) '
With wrdApp
'.Documents.Add
' .Visible = True
' Types the text
'.Selection.HomeKey Unit:=wdStory
'.Selection.TypeText Text:="Hello and Goodbye"
' The Real script
'Dim StartWord As String, EndWord As String
'StartWord = "Hello"
'EndWord = "Goodbye"
With .ActiveDocument.Content.Duplicate
.Find.Execute FindText:=startTag & "*" & endTag, MatchWildcards:=False
.MoveStart wdCharacter, Len(StardWord)
.MoveEnd wdCharacter, -Len(EndWord)
.Select ' Or whatever you want to do
End With
End With
With WrdDoc
.Close
End With
End If
End If
Next i
End Sub
Try this version, I suggest you try with a small batch of documents first as the document will be saved immediately after pasting the tag. (comment out the lines if you do not want to save and/or close):
Option Explicit
Private Sub PasteTagsToDocument()
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet1") 'Change to the correct name
Const startRow As Long = 5
Dim endRow As Long
endRow = ws.Range("B" & Rows.Count).End(xlUp).Row
Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Set wrdApp = New Word.Application
wrdApp.Visible = True
Dim i As Long
For i = startRow To endRow
Dim wrdPath As String
wrdPath = ws.Cells(i, 2).Value2
If wrdPath <> vbNullString Then
If Dir(wrdPath) <> vbNullString Then
Dim startTag As String
Dim endTag As String
startTag = ws.Cells(i, 3).Value2
endTag = ws.Cells(i, 4).Value2
Set wrdDoc = wrdApp.Documents.Open(wrdPath)
With wrdDoc
.Range(0, 0).InsertBefore startTag & vbNewLine
.GoTo(wdGoToPage, wdGoToAbsolute, 2).InsertBefore endTag & vbNewLine & startTag & vbNewLine
.GoTo(wdGoToPage, wdGoToAbsolute, 3).InsertBefore endTag & vbNewLine & startTag & vbNewLine
.Range.Paragraphs.Last.Range.InsertAfter vbNewLine & endTag
.Save 'Comment out if you do not want to save
.Close 'Comment out if you do not want to close the document
End With
Else
If MsgBox("File don't exist. " & vbNewLine & wrdPath & vbNewLine & "Click Ok to Continue or Cancel to stop the macro.", vbOKCancel) = vbCancel Then Exit For
End If
End If
Next i
Set ws = Nothing
Set wrdDoc = Nothing
wrdApp.Quit
Set wrdApp = Nothing
MsgBox "Complete!"
End Sub

Excel to Word VBA - Export data with a logo every x rows

I'm trying to create a set of plates (group of 5 rows with some data took from the mainsheet) and create a Word file that put 2 plate per page. Before every plate i wanna insert a logo (i'm trying to add the logo in the for cycle but i'm lost right now), with a custom style (the same as the result page)
I have part of the code i came up with until now, and i show you the result i'm trying to obtain:
(First pic the final result, the second the result i'm obtaining right now)
Option Explicit
Sub PrintLabels_Word()
Dim wb As Workbook, ws As Worksheet, wsPDF As Worksheet, xWs As Worksheet, WdObj As Object
Dim iLastRow As Long, ar(1 To 7, 1 To 1), rng As Range
Dim i As Long, r As Long, c As Integer, k As Integer
Dim LastRow As Long
Dim area As Range
Dim saveLocation As String
Dim strFileName As String, myRow As Long
Set wb = ThisWorkbook
Set ws = wb.Sheets("Summary")
Set wsPDF = wb.Sheets("Foglio1")
Set xWs = Application.ActiveSheet
wsPDF.Cells.Clear
xWs.ResetAllPageBreaks
' fixed
ar(1, 1) = ws.Cells(1, 10)
ar(2, 1) = "CLIENT: " & ws.Cells(1, 7)
ar(3, 1) = "ORDER" & " " & ws.Cells(2, 7)
ar(5, 1) = "JOB" & " " & ws.Cells(1, 2) & " " & ws.Cells(1, 3)
ar(6, 1) = "CASE NUMBER: 1/1"
iLastRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
r = 1 ' start row
c = 1 ' column A
For i = 6 To iLastRow
ar(4, 1) = "INSIDE CASE (TAG): " & ws.Cells(i, "H")
' fill plate
Set rng = wsPDF.Cells(r, c).Resize(7, 1)
rng.Value2 = ar
' merge cells
For k = 1 To 7
With rng.Cells(k, 1).Resize(1, 4)
.Merge
.HorizontalAlignment = xlCenter
.Font.Bold = True
End With
Next
r = r + 8
Next
MsgBox "Done"
With ActiveSheet.PageSetup
.Orientation = xlPortrait
.Zoom = 200
.FitToPagesTall = False
.FitToPagesWide = False
End With
Dim tblRange As Excel.Range
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim WordTable As Word.Table
iLastRow = wsPDF.Cells(Rows.Count, 1).End(xlUp).Row
Set tblRange = ThisWorkbook.Worksheets("Foglio1").Range("A1:D" & iLastRow)
On Error Resume Next
Set WordApp = GetObject(class:="Word.Application")
If WordApp Is Nothing Then Set WordApp = CreateObject(class:="Word.Application")
'WordApp.Visible = True
'WordApp.Activate
Set WordDoc = WordApp.Documents.Add
tblRange.Copy
WordDoc.Paragraphs(1).Range.PasteExcelTable _
LinkedToExcel:=False, _
WordFormatting:=False, _
RTF:=False
With WordApp
.ChangeFileOpenDirectory ThisWorkbook.Path
.ActiveDocument.SaveAs Filename:="Targhetta Adesiva" & " " & ws.Range("B3").Value & "_" &
ws.Range("G1").Value & ".doc"
.ActiveDocument.Close
End With
End Sub
You are trying to re-invent the wheel. Word already has all the functionality you need. It is called a mail merge (or Mailing) and it can use data from Excel.
To get multiple plates on one page, start with a Label merge setup and customise the layout table to suit your needs.
To do a mail merge with images, store all the images into one folder, put a unique image ID and each image path into the Excel source as two separate data columns. Then plug that information into the image merge field.
For more details see https://community.spiceworks.com/how_to/2675-using-mailmerge-to-insert-images
All that can be done without writing a single line of VBA.

Copy and Paste or append file from excel to word doc

ok, so here we go, I have tried to conquer this on my own for the past two days have have tried a lot of solutions. I am working with data in a Excel Spreadsheet that populates a word file. The specific problem I have is placing a table at the end of the word document. I have tried to create the table, and append a word doc that just has the table in it. nether seems to get done. My latest attempt was to just use sendkeys to copy and paste the table from the open documents.
I am willing to try anything at this point, short of doing it manually as I have to generate thousands of files.
Stripped code is below:
Option Explicit
Sub CreateWordDocuments()
Dim CustRow, CustCol, LastRow, TemplRow, DaysSince, FrDays, ToDays As Long
Dim DocLoc, TagName, TemplName, FileName As String
Dim TagValue As String
Dim myData As DataObject
Dim CurDt As Date
Dim LastAppDt As Date
Dim WordDoc As Object
Dim WordTable As Object
Dim WordApp As Object
Dim WordContent As Word.Range
Dim oWorkbookEA As Workbook
Set oWorkbookEA = Workbooks.Open(FileName:="M:\Form.xlsx")
Set myData = New DataObject
Dim oTable As Table
Dim oCell As Cell
Dim oPrevRow As Row, oNewRow As Row
Dim iColumn As Long
Dim myRange As Range
Dim NoCol As Integer
Dim NoRow As Integer
With Sheet1
DocLoc = "M:\WIP_Rev4.docx" 'Word Document Filename
'Open Word Template
On Error Resume Next 'If Word is already running
Set WordApp = GetObject("Word.Application")
If Err.Number <> 0 Then
'Launch a new instance of Word
Err.Clear
'On Error GoTo Error_Handler
Set WordApp = CreateObject("Word.Application")
WordApp.Visible = True 'Make the application visible to the user
End If
Set WordTable = WordApp.Documents.Open(FileName:="M:\Table.docx", ReadOnly:=True)
LastRow = .Range("E9999").End(xlUp).Row 'Determine Last Row in Table
For CustRow = 6 To 7 'LastRow
DaysSince = .Range("M" & CustRow).Value
Set WordDoc = WordApp.Documents.Open(FileName:=DocLoc, ReadOnly:=False) 'Open Template
'For CustCol = 5 To 13 'Move Through 9 Columns
TagValue = .Cells(CustRow, 2).Value 'Tag Value
With WordDoc.Content.Find
.Text = "$Product$"
.Replacement.Text = TagValue
.Wrap = wdFindContinue
.Execute Replace:=wdReplaceAll 'Find & Replace all instances
End With
myData.SetText oWorkbookEA.Sheets("Company Info").Shapes("TextBox 6").TextFrame.Characters.Text
myData.PutInClipboard
With WordDoc.Content.Find
.Text = "$VarS$"
.Replacement.Text = "^c"
.Wrap = wdFindStop
.Execute Replace:=wdReplaceOne 'Find & Replace all instances
End With
myData.SetText oWorkbookEA.Sheets("Company Info").Shapes("TextBox 14").TextFrame.Characters.Text
myData.PutInClipboard
'This table works fine as it is preexisting
Set oTable = WordDoc.Tables(4)
Set oPrevRow = oTable.Rows(oTable.Rows.Count)
oPrevRow.Cells(1).Range.Text = "Ingredient Name"
oPrevRow.Cells(2).Range.Text = "No."
oPrevRow.Cells(3).Range.Text = "Percentage"
oTable.Rows.Add
Set oNewRow = oTable.Rows(oTable.Rows.Count)
oNewRow.Cells(1).Range.Text = "Lidocaine"
oNewRow.Cells(2).Range.Text = ""
oNewRow.Cells(3).Range.Text = Format(.Range("E" & CustRow).Value, "#.#%")
oTable.Rows.Add
Set oNewRow = oTable.Rows(oTable.Rows.Count)
oNewRow.Cells(1).Range.Text = "Glycol"
oNewRow.Cells(2).Range.Text = ""
oNewRow.Cells(3).Range.Text = Format(.Range("F" & CustRow).Value, "#.#%")
oTable.Rows.Add
Set oNewRow = oTable.Rows(oTable.Rows.Count)
oNewRow.Cells(1).Range.Text = "Glycerin"
oNewRow.Cells(2).Range.Text = ""
oNewRow.Cells(3).Range.Text = Format(.Range("G" & CustRow).Value, "#.#%")
'With WordDoc
' .Tables(.Tables.Count).Rows(1).Cells(1).Select
' MsgBox (.Tables.Count)
'End With
With oTable.Borders
.InsideLineStyle = wdLineStyleSingle
'.OutsideLineStyle = wdLineStyleDouble
End With
'The begining of my problems
WordDoc.Selection.Collapse Direction:=wdCollapseEnd
WordTable.Active
WordTable.SendKeys ("^a")
WordTable.SendKeys ("^c")
WordDoc.Active
WordDoc.SendKeys ("^v")
FileName = ThisWorkbook.Path & "\" & .Range("A" & CustRow).Value & "_" & ".pdf" 'Create full filename & Path with current workbook location, Last Name & First Name
WordDoc.ExportAsFixedFormat OutputFileName:=FileName, ExportFormat:=wdExportFormatPDF
WordDoc.Close False
.Range("N" & CustRow).Value = TemplName 'Template Name
.Range("O" & CustRow).Value = Now
WordDoc.PrintOut
WordDoc.Close
'Kill (FileName) 'Deletes the PDF or Word that was just created
Next CustRow
WordApp.Quit
End With
End Sub
Table document is Table.docx that I have tried to append to the end. That would be my ideal solution.
Thanks for any help you can give
Here's an example of copying a table from one document and pasting it at the end of another:
Sub Tester()
Dim wd As Word.Application
Dim docTbl As Word.Document, docMain As Word.Document
Dim tbl As Word.Table, objRange As Word.Range
Set wd = GetObject(, "Word.application") 'Word already running with the 2 docs open
Set docMain = wd.Documents("Document1")
Set docTbl = wd.Documents("Document2")
Set tbl = docTbl.Tables(1)
tbl.Range.Copy '<< copy the table
Set objRange = docMain.Content
objRange.Collapse Direction:=0 'wdCollapseEnd
objRange.InsertAfter vbCrLf
objRange.Collapse Direction:=0
objRange.Paste '<< paste the table
End Sub
FYI I find the dataobject.putinclipboard approach pretty unreliable in later versions of Excel, so I'd avoid that if you can.

How do I transfer formatted text from Word to Excel?

The below code is copied data from MS Word (content control) to Excel. However, when I copy text with bullet and paste into Excel, it removes the bullets and pastes the text only.
How can I copy bullets from the content control?
Sub getWordFormData()
Dim wdApp As New Word.Application
Dim myDoc As Word.Document
Dim CCtl As Word.ContentControl
Dim myFolder As String, strFile As String
Dim myWkSht As Worksheet, i As Long, j As Long
myFolder = "enter folder path" '<< enter you folder path for the word document
If Dir(myFolder & "\" & "*.*") = "" Then
Application.ScreenUpdating = True
MsgBox "The folder is empty."
Exit Sub
End If
Set myWkSht = ActiveSheet
ActiveSheet.Cells.Clear
Range("A1") = "Test 1"
Range("B1") = "Test 2"
Range("A1:B1").Font.Bold = True
i = myWkSht.Cells(myWkSht.Rows.Count, 1).End(xlUp).Row
strFile = Dir(myFolder & "\*.docx", vbNormal)
While strFile <> ""
i = i + 1
Set myDoc = wdApp.Documents.Open(Filename:=myFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
With myDoc
j = 0
For Each CCtl In .ContentControls
j = j + 1
myWkSht.Cells(i, j) = CCtl.Range.Text
Next
myWkSht.Columns.AutoFit
End With
myDoc.Close SaveChanges:=False
strFile = Dir()
Wend
wdApp.Quit
Set myDoc = Nothing: Set wdApp = Nothing: Set myWkSht = Nothing
Application.ScreenUpdating = True
End Sub
try with this block
With myDoc
j = 0
For Each CCtl In .ContentControls
j = j + 1
CCtl.Range.Copy
myWkSht.Cells(i, j).PasteSpecial Paste:=xlPasteValues
Next
myWkSht.Columns.AutoFit
End With

Resources