http://social.msdn.microsoft.com/For...d-9bccf025f007 - I found this but when I try and adapt it to my code the blue underline appears, I'm thinking I don't have the correct references added, but I wouldn't have a clue which ones I need.
http://social.msdn.microsoft.com/For...d-9bccf025f007 - I found this but when I try and adapt it to my code the blue underline appears, I'm thinking I don't have the correct references added, but I wouldn't have a clue which ones I need.
try this:
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
That works! Thank-you very much![]()
if you're not sure about the references, you can check them in the example. it uses Microsoft Word 12.0 Object Library which you'll find on the references COM tab
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
Hi Paul,
Nevermind, I just figured out why it wasn't working. It doesn't like being split up onto a couple of lines.
I've gone through and added more grid views to the code you've given me, and I'm coming up with an error which I'm sure the answer to is simple; but my thinking currently isn't at its best haha.
It's saying that 'dgvs' isn't declared, when it definitely is. Here's the part where the object is declared:
Sorry to trouble you about this again, I just can't see why it isn't working.Code:'Bookmarks are "grid1" (relates to DataGridView1), + "grid2" (relates to DataGridView2) Dim dgvs(,) As Object = {{dgAssetsSummary, "AssetsSummary"}, {dgLiabilitiesSummary, "LiabilitiesSummary"}, {dgAssetsFull, "AssetsFull"}, & _ {dgLiabilitiesFull, "LiabilitiesFull"}, {dgPAEFull, "PAEFull"}, {dgGoalsMediumTerm, "GoalsMediumTerm"}, & _ {dgGWStopped, "GWStopped"}, {dgGWAdded, "GWAdded"}, {dgFLSum, "FLSums"}}
Thankyou,
Verra
Last edited by Verra; May 25th, 2011 at 08:07 PM.
I'm thinking in adapt this example to export one list to excel but i get the following error:
haven't changed a thing. only saw the dependencies if the excel dependence was at fault but it was there. the 'export to word' button works perfectly
Hi .Paul
Two more questions about how to export DGV to Word.
1) Your sample code exports the DGV to a new Word document. What's the code for exporting the DGV to a document that's opened in Word, I mean append the DGV to the end of that open Word document ? Attention: the document must not be opened, it IS open in Word.
2) What is the code to align the text in the Word table cells to the right instead of left ?
I applied successfully your sample code, but I couldn't figure out how to do what I asked in the previous questions.
Thanks
Jacques
the problem with a document that IS open in Word is finding a way to refer to it.
2/ 'align right
oTable.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
Thank you paul for your help.
I already applied sucessfully your answer to my second question.
As to the first problem - copying the DGV to an opened Word document - I have the following code in VBA to copy the contents of a worksheet to an open Word document and it's working like a charm. Unfortunately I'm not able to write similar code in Visual Basic.
Do you see something in that code that gives you an idea?Code:Sub CopyFromExcel2VisibleOpenWordDoc() Dim WrdApp As Object Dim WrdDoc As Object Dim LastRow As Long Dim lRow As Long Dim iCol As Integer LastRow = 0 On Error Resume Next Set WrdApp = GetObject(, "Word.Application") If WrdApp Is Nothing Then MsgBox "MS Word is not available!" _ & vbCrLf & "Start MS Word" _ & vbCrLf & "and put the cursor at the right place" _ & vbCrLf & "in the right document!", vbExclamation End If For iCol = 1 To 6 lRow = Cells(65536, iCol).End(xlUp).Row If lRow > LastRow Then LastRow = lRow Next iCol 'Copy from last row to begin table ActiveSheet.Range(Cells(1, "A"), Cells(LastRow, "F")).Copy With WrdApp .Visible = True .Activate Set WrdDoc = WrdApp.ActiveDocument 'WrdDoc.Show With WrdDoc .Activate .Application.Selection.TypeParagraph .Application.Selection.Paste End With End With Application.CutCopyMode = False End Sub
ok. using my code, change:
vb.net Code:
' Create Word Application Dim oWord As Word.Application = DirectCast(CreateObject("Word.Application"), Word.Application)
to:
vb.net Code:
Dim oWord As Word.Application Try ' Get Word Application oWord = DirectCast(GetObject(, "Word.Application"), Word.Application) Catch ex As Exception MsgBox("Can't find Word Document", MsgBoxStyle.Information) Return End Try
Last edited by .paul.; Oct 12th, 2012 at 12:46 PM.
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
Thank you paul.
Unfortunately the DGV is still added to a NEW opened Word document. The DGV is NOT added to the Word document that is already open.
Maybe the problem is due to this code in your code:
Code:Dim oDoc As Word.Document = oWord.Documents.Add
ok. post the code you tried. i'll see if i can find the error.
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
Dim oDoc As Word.Document = oWord.ActiveDocument
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
referring to the ActiveDocument did the trick finally
Thank you veru much, paul.
Now we have 2 sample codes: 1 to copy a DGV to a new Word document and 1 to copy it (append it) to an open Word document.
Nice![]()
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
Yes, I did paul, but I couldn't use the code in that example.
But you are right indeed: there are not 2 but 3 examples. My fault![]()
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
paul
After the DGV has been exported to MS Word table, I experience an annoying problem: the content in the Word table cells is not formatted as I want it to be.
After the date, the time is added ("00:00:00") and the numbers have too many decimal places (instead of 2).
I have tried to resolve this problem by first converting the DGV cells values using standard numeric format strings (ToString method) before pasting them to the Word table, but I am not very happy with this method, because then my DGV values aren't usable anymore (converted to strings) and I am forced to remove them all from the DGV and to enter all the data again, if I want to calculate results once more.
I guess it would be better to format the Word table cells content directly after pasting the DGV to Word, but honestly I don't know how to manage that.
I would be grateful if you could give me some code to insert in your existing code to format the Word table cells content for dates and numbers the way the dates don't have the time added and the decimal places for the numbers are limited to 2.
Thanks.
Hello paul
1) Still no answer possible to my post #59?
2) How to adapt your code to copy NOT the ENTIRE DataGridView to Word, but only the SELECTED area (with mouse e.g.) of the DataGridView, thus the selected columns and rows?
Thanks & best regards
Jacques
1/ i'm not sure of how to tackle that. it'd probably be best to format the dateTime in the items array after reading the dgv
2/ that's a whole new program. there are plenty of examples either here on vbforums or you can find them through google. sorry i couldn't be more help.
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
Here are the errors I get from this code
![]()
ok I got it
change
to thisCode:Excel.ApplicationClass xlapp = new Excel.ApplicationClass();
Code:Excel.Application xlapp = new Excel.Application();
you're not using excel 2007 then... sorry i didn't get back to you earlier.
![]()
![]()
if this helps, rate me
![]()
![]()
irregular regions | numericTextbox | keycodes | removing control properties | hotkeys | rtf printing | Extended RichTextBox | iconWorks | readonly listbox | sort listview | screen capture | relational listForms | countDown timer | animated notifyIcon form | dynamic crystal report | move / resize runtime controls | reOrderable DnD listview / listbox | self closing message box | searchable list(of class) | cursor from bitmap | (VB2008+) Textbox - GetFirstVisibleLineIndex / GetLastVisibleLineIndex | vb2008 extensions | Paint lite.Net | calculator | inline calculator | export listview to word table | imperial~metric converter | export DGV to word ~ excel | globalInputHook | dropDown Calendar control | International Time + Currency | GDI+ gauge | quizControl | extended dgv
My Web Site....
Maths Revision V1.0
Play Connect4 against your PC (java Applet)
Not a problem..yeah I'm using 2010