Reading values from Excel Columns

S

sorcerer

Hi VBA guys.
See I have an assignment.
I have to read column and cell values from Excel work sheets and use
them in another word file.
eg. one column might have a header called Font.
I have to read the value from this cell, and use the font
in another document for changing the font. Is it possible to implement
this idea. And hey I am new to working with excel VBA.
Is it very difficult to code this I mean just reading values,
from one excel file and use them in another word file.
 
H

Helmut Weber

Hi,
(reference to excel-library needed,
extras references),
then
lets say you have an excel worksheet,
with "size" in one of the cells in the first row,
with the values 8, 9, 10, 11, 12 in the following rows
in the same column.

then
create a new excel.application,
open the workbook in question,
select the first row in the first worksheet
which gives you the column to search
and while the next cell in the same column
contains data, format e.g. the corresonding
paragraph in you doc in the font.size read
from the excel sheet.

If you decide to set the excel.application
to visible = false, then make sure to destroy
both the objects excel.application und excel.workbook
before the end of your macro.

My code is in no way optimized.
I just wanted to show the very basics.
Beware of linebreaks by the newsreader
' ----------
Dim r As Long ' row
Dim c As Long ' column

Dim oExc As Excel.Application
Dim wExc As Excel.Workbook
Set oExc = New Excel.Application
Set wExc = oExc.Workbooks.Open("c:\test\fontbook.xls")
oExc.Visible = True
wExc.Worksheets(1).Rows("1:1").Select
oExc.Selection.Find(What:="Size").Activate
r = oExc.ActiveCell.Row
c = oExc.ActiveCell.Column
r = r + 1
With wExc.Worksheets(1)
While .Cells(r, c).Value <> ""
ActiveDocument.Range.Paragraphs(r -
1).Range.Font.Size = .Cells(r, c).Value
r = r + 1
Wend
End With
' ...

End Sub

' ----------


See, too:
http://www.word.mvps.org/faqs/interdev/ControlXLFromWord.ht
m

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top