PDA

View Full Version : Excel logging file for word document



hunsnowboard
05-04-2009, 10:49 AM
HI Everyone! I hope you can help me as I am a very beginner in VBA and cannot solve the following problem.

I have an excel file which logs the information entered in a word document.
Right now I have to open the excel file to log this information.

What I would like the macro to do s the following:

1. First to check if the excel file (nyilvantartas_v5.xls) is present in the same directory were the word document is. If not present then show a message box that the excel file is not in the directory and exit sub.

2. If the excel file is present in the directory but it is not open then open it.

3. If the excel file is present and opened, then do nothing.

At present the code looks like this:


Dim xLapp As Object, xLbook As Object, xLsheet As Object, wBook As String, lastRow As Long, fileName As String, myRange As Range, myRef As String, appOpen As Boolean
wBook = "I:\Munka\Közérdekű bejelentés\nyilvantartas_v5.xls"
appOpen = True

Set xLapp = GetObject(, "Excel.Application")
Set xLbook = xLapp.workbooks("nyilvantartas_v5.xls")
Set xLsheet = xLbook.worksheets(ugynev.Value)


Thank you for your help in advance!