Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
How can I edit my macro to export a table to excel so that Columns C-J have a width of 250?
FUNCTION ExcelExport(CH176)
set obj = ActiveDocument.GetSheetObject( CH176)
w = obj.GetColumnCount
if obj.GetRowCount>1001 then
h=1000
else h=obj.GetRowCount
end if
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
objExcel.Worksheets(1).select()
objExcel.Visible = True
set CellMatrix = obj.GetCells2(0,0,w,h)
column = 1
for cc=0 to w-1
objExcel.Cells(1,column).Value = CellMatrix(0)(cc).Text
objExcel.Cells(1,column).EntireRow.Font.Bold = True
column = column +1
next
c = 1
r =2
for RowIter=1 to h-1
for ColIter=0 to w-1
objExcel.Cells(r,c).Value = CellMatrix(RowIter)(ColIter).Text
c = c +1
next
r = r+1
c = 1
next
END FUNCTION
SUB ExportKanban
ExcelExport( "CH176" )
END SUB
FUNCTION ExcelExport(CH176)
set obj = ActiveDocument.GetSheetObject( CH176)
w = obj.GetColumnCount
if obj.GetRowCount>1001 then
h=1000
else h=obj.GetRowCount
end if
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
objExcel.Worksheets(1).select()
objExcel.Visible = True
'Column C
objExcel.Worksheets(1).Columns(3).ColumnWidth = 250
set CellMatrix = obj.GetCells2(0,0,w,h)
column = 1
for cc=0 to w-1
objExcel.Cells(1,column).Value = CellMatrix(0)(cc).Text
objExcel.Cells(1,column).EntireRow.Font.Bold = True
column = column +1
next
c = 1
r =2
for RowIter=1 to h-1
for ColIter=0 to w-1
objExcel.Cells(r,c).Value = CellMatrix(RowIter)(ColIter).Text
c = c +1
next
r = r+1
c = 1
next
END FUNCTION
See if this post can help answer your question:
thanks, but i have seen that and am not sure how to get it to work in my script
It didn't work when i tried
I put the following into one of my macros and it worked:
xlSheet.Columns(1).ColumnWidth = 250
Just number the columns accordingly.
where in the script did you insert that line?
doesn't seem to work. I'm kind of guessing where it's supposed to go
FUNCTION ExcelExport(CH176)
set obj = ActiveDocument.GetSheetObject( CH176)
w = obj.GetColumnCount
if obj.GetRowCount>1001 then
h=1000
else h=obj.GetRowCount
end if
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
objExcel.Worksheets(1).select()
objExcel.Visible = True
'Column C
objExcel.Worksheets(1).Columns(3).ColumnWidth = 250
set CellMatrix = obj.GetCells2(0,0,w,h)
column = 1
for cc=0 to w-1
objExcel.Cells(1,column).Value = CellMatrix(0)(cc).Text
objExcel.Cells(1,column).EntireRow.Font.Bold = True
column = column +1
next
c = 1
r =2
for RowIter=1 to h-1
for ColIter=0 to w-1
objExcel.Cells(r,c).Value = CellMatrix(RowIter)(ColIter).Text
c = c +1
next
r = r+1
c = 1
next
END FUNCTION
thanks!