Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with some VB code to update an Excel worksheet

Status
Not open for further replies.

B555

Technical User
Feb 7, 2005
36
US
I have a pivot table built in Excel that is built from an access DB. I need to find a way to Update the Data tab, but not the Pivot tbl tab. I have logic that deletes all tabs and creates new work sheets, but I can't get it to only update the worksheet I want and leave the other work sheets alone. It seems so simple, yet I ca't get it to work. I will attach a copy of what I discribed above.

Private Sub GenReport_Click()

Dim qdf As QueryDef, fs
Dim obj_XL_App As Excel.Application
Dim obj_XL_Wkbk As Excel.Workbook
Dim obj_XL_Wksht As Excel.Worksheet
Dim rst As Recordset
Dim sSQL As String
Dim c As Range
Dim MyRng As Range
Dim x As Integer

On Error GoTo Err_cmdRunGenReport
txtReportfile = "\\Dom1\Shared\Intermodal\Shared Docs\INTERMODAL\T to C Conversion\BoxTest.xls"
Me.Requery

DoCmd.SetWarnings False

With CurrentDb
Set fs = CreateObject("Scripting.FileSystemObject")
fs.DeleteFile txtReportfile
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Detail", txtReportfile, True

End With
Set fs = Nothing

Set obj_XL_App = CreateObject("Excel.Application")
Set obj_XL_Wkbk = obj_XL_App.Workbooks.Open(txtReportfile)



'---------------------------------------------------------------------
'Format to Wkly HZ Lds tab

obj_XL_App.Sheets("MonthlyReport3").Select
obj_XL_App.Rows("1:1").Select
obj_XL_App.Selection.Font.Bold = True
obj_XL_App.Columns("A:K").EntireColumn.AutoFit
obj_XL_App.Columns("A:K").EntireColumn.WrapText = True

obj_XL_App.Range("H:H,I:I").Select
obj_XL_App.Selection.NumberFormat = ".00"

obj_XL_App.Range("F:F,G:G").Select
obj_XL_App.Selection.NumberFormat = "mm-dd-yy h:mm"

obj_XL_App.Range("A1:K1").Select
obj_XL_App.Selection.Interior.ColorIndex = 15
'obj_XL_App.Selection.RowHeight = 25
'obj_XL_App.Selection.WrapText = True
obj_XL_App.Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
obj_XL_App.Selection.Borders(xlEdgeLeft).Weight = xlThin
obj_XL_App.Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
obj_XL_App.Selection.Borders(xlEdgeTop).Weight = xlThin
obj_XL_App.Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
obj_XL_App.Selection.Borders(xlEdgeBottom).Weight = xlThin
obj_XL_App.Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
obj_XL_App.Selection.Borders(xlEdgeRight).Weight = xlThin
obj_XL_App.Selection.Borders(xlInsideVertical).LineStyle = xlContinuous
obj_XL_App.Selection.Borders(xlInsideVertical).Weight = xlThin
obj_XL_App.Selection.HorizontalAlignment = xlCenter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top