|
-
Sep 19th, 2005, 09:26 PM
#1
Thread Starter
Member
Problem To Move To 2nd Worksheet
I have a problem with my coding when wants to move all the data to the second worksheet. I try to change the setting to make the output in 2nd worksheet, but it didnt work.
this is my code:
VB Code:
Set objExcel = CreateObject("excel.application") 'Starts the Excel Session
Set objBook = objExcel.Workbooks.Add 'Add a Workbook
Set objSheet = objBook.Worksheets.Item(1) 'Select a Sheet
objExcel.Application.Visible = True
objExcel.Application.Cells(1, 1).Value = "Kod Kategori BA"
objExcel.Application.Cells(1, 2).Value = "No.BA"
With objExcel
.Application.Cells(n, 1).Value = ((Trim(DataHRMIS.Recordset.Fields("BACatCd").Value)))
.Application.Cells(n, 2).Value = ((Trim(DataHRMIS.Recordset.Fields("BANo").Value)))
end with
i try to change here, but it still dont work!
VB Code:
Set objSheet = objBook.Worksheets.Item(2)
how can i fix this? anyone plz help me...tq
-
Sep 19th, 2005, 09:46 PM
#2
Re: Problem To Move To 2nd Worksheet
Moved from Classic VB forum.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 19th, 2005, 09:52 PM
#3
Re: Problem To Move To 2nd Worksheet
Your not using the book or sheet objects and running everything off ogf the application object which is incorrect. 
VB Code:
Set objExcel = CreateObject("excel.application") 'Starts the Excel Session
Set objBook = objExcel.Workbooks.Add 'Add a Workbook
Set objSheet = objBook.Sheets.Item(2) 'Select second Sheet
objExcel.Visible = True
objSheet.Cells(1, 1).Value = "Kod Kategori BA"
objSheet.Cells(1, 2).Value = "No.BA"
With objSheet
.Cells(n, 1).Value = ((Trim(DataHRMIS.Recordset.Fields("BACatCd").Value)))
.Cells(n, 2).Value = ((Trim(DataHRMIS.Recordset.Fields("BANo").Value)))
End With
Set objSheet = Nothing
objBook.Close True
Set objBook = Nothing
objExcel.Quit
Set objExcel = Nothing
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 20th, 2005, 01:05 AM
#4
Thread Starter
Member
Re: Problem To Move To 2nd Worksheet
Thanks RobDog8888!
I've tried the code already but it didnt work! it still display all the data in sheet 1.
No changes from the previous one..
-
Sep 20th, 2005, 07:35 PM
#5
Thread Starter
Member
Re: Problem To Move To 2nd Worksheet
hello guyz..is there anybody can help me on this? my system still cannot give output to the 2nd worksheet....
-
Sep 20th, 2005, 08:08 PM
#6
Re: Problem To Move To 2nd Worksheet
Are you just trying to add data to "Sheet2" or a different workbook?
VB Code:
Set objSheet = objBook.Sheets.Item("Sheet2") 'Set to second Sheet2 or #2
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 20th, 2005, 09:05 PM
#7
Thread Starter
Member
Re: Problem To Move To 2nd Worksheet
actually, i need to do both..But first, i try it to add data to sheet 2 within same work book.. i try both
VB Code:
Set objSheet = objBook.Sheets.Item("Sheet2")
and also this way:
VB Code:
Set objSheet = objBook.Sheets.Item(2)
both of this code not succesfull..
-
Sep 20th, 2005, 10:01 PM
#8
Re: Problem To Move To 2nd Worksheet
It really should be working but could you post the code you are using?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 20th, 2005, 11:19 PM
#9
Thread Starter
Member
Re: Problem To Move To 2nd Worksheet
hey Rob, I got it already.
I cannot use objSheet to declare it!
i used this way :
VB Code:
Set objExcel = CreateObject("excel.application") 'Starts the Excel Session
Set objBook = objExcel.Workbooks.Add 'Add a Workbook
objExcel.Sheets("Sheet1").Select
objExcel.Sheets("Sheet1").Name = "Maklumat BA"
This code works to me!
But how can I format the cell to be in Text?
It because, when i send the data from DB to excel, excel cannot read '07'..
it only can recognize 7..
Anyway, thanks to you to be so concern! TQ
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|