Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel VBA from Word Template

I have a Word template that creates a reference number
and collects information for the document from the user.
I am trying to input the information gathered from each
new document into an Excel Spreadsheet.

I have it working up to a point. It opens the Excel
file, finds the next empty row, then enters all the info
from the Word template, closes the file.

The problem I have is that it acts strangely if you
already have Excel open. The macro runs and enters the
data into the spreadsheet fine, but the next time you go
to open the Excel spreadsheet, you can only see it by
unhiding the window. This doesn't happen if Excel was
not open when the macro was run and it exits Excel at the
end of the macro.

This template is for basic users, and I don't want to
have to give them conditions for using the templates
(like having Excel closed), as they probably just won't
use it if I do that.

The code I'm using is the following:

Sub GetExcel()

QuoteRef = ThisDocument.Variables("QuoteRef")

Dim MyXL As Object ' Variable to hold reference
' to Microsoft Excel.
Dim ExcelWasNotRunning As Boolean ' Flag for final
release.

On Error Resume Next ' Defer error trapping.

Set MyXL = GetObject(, "Excel.Application")
If Err.Number < 0 Then ExcelWasNotRunning = True
Err.Clear ' Clear Err object in case error
occurred.

Set MyXL = GetObject("C:\File.xls")

MyXL.Application.Visible = True
MyXL.Parent.Windows(1).Visible = True
MyXL.Application.ScreenUpdating = False
MyXL.activesheet.Range("A1").Select

Dim i As Integer

i = 1

For i = 1 To 200
If MyXL.activesheet.Range("a" & i) = "" Then
GoTo Continue
End If
Next

Continue:

MyXL.activesheet.Range("A" & i) = QuoteRef
MyXL.activesheet.Range("B" & i) = "LINK"
MyXL.activesheet.Range("C" & i) = "SalesProp"
MyXL.activesheet.Range("D" & i) = Date
MyXL.activesheet.Range("E" & i) = form1.cbxSalesman
MyXL.activesheet.Range("F" & i) = form1.cbxCustomer
MyXL.activesheet.Range("G" & i) = form1.txtTitle

With MyXL.activesheet
.Hyperlinks.Add .Range("B" & i).Cells(1, 1),
ActiveDocument.FullName
End With

MyXL.activesheet.Range("A" & i).Select

MyXL.Application.ScreenUpdating = True

MyXL.Activeworkbook.Save

If ExcelWasNotRunning = True Then
MyXL.Application.Quit
Else
MyXL.ActiveWorkbook.Close
End If

Set MyXL = Nothing

End Sub

Any suggestions or work-arounds anyone has used would be
greatly appreciated

Thanks, Chesney
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I link between a Word template and an Excel template Josh Excel Discussion (Misc queries) 0 April 1st 08 12:36 AM
Opening a Word Template from within Excel perry Excel Worksheet Functions 0 January 30th 07 12:23 PM
Opening a Word template from excel RealmSteel Excel Discussion (Misc queries) 3 November 29th 06 09:16 PM
Sending from excel to word template pizdus Excel Discussion (Misc queries) 0 January 17th 06 05:57 PM
Word Template - Editing Excel with VBA chesney Excel Programming 0 June 17th 04 09:29 AM


All times are GMT +1. The time now is 02:11 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"