Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2006

Tip: Looking for answers? Try searching our database.

How to refer to excel cells attribute

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alex St-Pierre - 19 Mar 2006 18:30 GMT
Hi, I would like to use excel property in Word VBA.
The problem I have is that I format Word Table using Table in Excel and
would like to adjust to table depending of all cells format in excel.
So, I open the Excel workbook and copy a table value to word. I would like
to refer to Excel cells borders and text style (ex: bold) to be able to
adjust word table but doesn't know how  ?

   Dim appExcel As Object
   Dim wbExcel As Object
   Dim rngExcel as Range
   Dim tbl As Word.Table
   Dim DocWord1 As Word.Document
   Dim strData as String
   Set DocWord1 = AppWord.ActiveDocument
   PathExcel = "table.xls"
   Set appExcel = GetObject(, "Excel.Application")
   Set tbl = DocWord1.Tables(2)
   Set wbExcel = appExcel.Workbooks(PathExcel)
   Set rngExcel = wbExcel.Sheets("table1.1").Range("Table1_1")
   Set tbl = DocWord1.Tables(2)
   DerLigneExcel = rngExcel.Rows.Count
   DerLigneWord = tbl.Rows.Count
   j = DerLigneExcel - DerLigneWord  
   For k = 1 To j
          tbl.Rows.Add
   Next k
   For k = 1 To -j
          tbl.Cell(5, 1).Select
   Selection.SelectRow
          Selection.Rows.Delete
   Next k
   With tbl
       For i = 1 To tbl.Rows.Count
       For j = 1 To tbl.Columns.Count
              strData = rngExcel.Cells(i, j)
              strData = Format(strData, "#,##0;(#,##0)")
              .Cell(i, j).Range.Text = strData
'I would like to say:
' If rngExcel.Cells(i, j).Borders(x1EdgeTop).LineStyle = x1continue Then
'      etc.
'      End If  'Also, if this work, I will be able to check if the style is
bold.

       Next j
       Next i

Thanks.
Signature

Alex St-Pierre

Helmut Weber - 19 Mar 2006 21:57 GMT
Hi Alex,

use early binding:

http://word.mvps.org/faqs/interdev/EarlyvsLateBinding.htm

See also:
http://word.mvps.org/faqs/interdev/controlxlfromword.htm
http://word.mvps.org/faqs/interdev/controlwordfromxl.htm

Without looking into you code precisely,
it's probably the excel constants,
which are causing trouble,
because they are unknow to Word with late binding.

also, with
> Dim rngExcel as Range
rngExcel is a word range.

Should be:
> Dim rngExcel as Excel.Range  

Plus
(x1EdgeTop).LineStyle = x1continue

should be xlEdgeTop and xlcontinue, I suppose.

Note the differnce: not "x1", but "xl".

So far for a beginning.

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"

Alex St-Pierre - 20 Mar 2006 19:27 GMT
Hi Helmut,
With Early Binding, all works good. I can write my code as I write it in
Excel VBA.
This morning, since I opened the document from office XP, in
Tools/Reference, I had to set the object library version 10.0. ("Missing:
Microsoft Excel 11.0 Object Library")

The program I am creating will be used by a lot of people from office xp
version to newest. Is there a way to add things in my Macro that will replace:
"Missing: Microsoft Excel 11.0 Object Library" by the last Microsoft Excel
Object Library available ? (and, if available, add a line that remove all
missing status)
Thanks,
Signature

Alex St-Pierre

"Helmut Weber" a écrit :

> Hi Alex,
>
[quoted text clipped - 26 lines]
>
> So far for a beginning.
Helmut Weber - 21 Mar 2006 09:12 GMT
Hi Alex,

you may use early binding for development.
Use the numeric values of the Word-constants.
Use late binding when testing is finished.

Signature

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.