From Access VBA I need to do things to Excel window open from within a SUB function
What is good practice to call an open Excel workbook (from Access) so I can manipulate it (Copy tab, add rows, remove blanks)?
Code:
Sub PopulateExcel(strName, strNameID, strPractice, strRole, strServiceType, strFileName)
Dim MySheetName As String
Dim MyXL As Object
' Set MyXL = excel_App.Workbooks.c
'copy Sheet1
Set MyXL = AppActivate.Workbooks(strFileName).Windows(1).Caption
Select Case strRole
Case "CRM"
Debug.Print "Making CRM tab"
'open Excel file as defined in CompiledDirectory
'set focus on new EXCEL filename
MyXL.Sheets(1).copy after:=MyXL.worksheets(MyXL.worksheets.Count) 'copy TAMPLATE tab and place it after all sheets
MySheetName = strNameID & "-" & strName 'rename new tab
Debug.Print "New Tab Name = '" & MySheetName & "'"
ActiveSheet.Name = MySheetName 'activate new sheet
'begin populating tab with custom information pertaining to Associate
MyXL.ActiveSheet.range("B5") = strPractice & " " & strRole & " Assessment Form"
Let me know if you need to know more. My apologies for the possible randomness of the code, I am learning how to go from Access VBA, call to create an Excel workbook, copy the one tab (called TEMPLATE) to last worksheet (because there will be more sheets as it goes). Hence I found I can make a sub to do the Excel Manipulation. The catch is I am uncertain what is carrying forward from Function vs needing to re-declare variables, etc.
Thanks!
Rob