Question : How do I copy a template excel sheet in the same workbook in order to populate the new sheet with data from my database

ok,
I have been trying to fix this and research info for HOURS!
I currently have a template worksheet that successfully copies itself to a new sheet. the problem I am encountering is: I DO NOT want excel to pop up(open) when the copy takes place. it looks horrible and it leaves residual excel drawings on my progress bar form that is running. I will post some code to show what I am talking about.

if you look at my code, you will see the following occuring on each line:

1) export file type is BGW, run code in IF
2) assign my excel sheet object "oSheet" equal to sheet 3 (template sheet)
3) make sure excel can see the sheet to copy it by turning visibility on
4) unprotect the sheet with the password (yes, I changed it before uploading)
5) perform the copy of the current sheet (this is where the excel app pops open for the user to see. I DO NOT WANT THAT TO HAPPEN! please help with this part!
6) tell excel to go away, I dont want to see it (this is a temp fix i tried, but it is still annoying!
7) tell excel i dont want user control
8) set the template excel sheet back to hidden
9) name the new copy of the template according to a string i stored elsewhere.
10) password protect the template sheet
11) change the current oSheet to the newly created copy of the template
12) Unprotect the new sheet
13)  make certain the sheet will be visible to the user when the export is completed
14) password protect the sheet
any code after this point is inconsequential

I thank anyone who will try to help and will bow before anyone who can successfully help me solve this problem! :)
Thank you in advance!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
If exportFileType = "BGW" Then
                oSheet = oBook.Sheets(3)
                oSheet.Visible = Excel.XlSheetVisibility.xlSheetVisible = True
                oSheet.Unprotect("PassW0rd")
                oSheet.Copy(After:=oSheet)
                oApp.Visible = False
                oApp.UserControl = False
                oSheet.Visible = Excel.XlSheetVisibility.xlSheetVeryHidden = True
                oBook.Sheets("Sheet TEMPLATE (2)").Name = strSheet
                oSheet.Protect("PassW0rd")
                oSheet = oBook.Sheets(strSheet)
                oSheet.Unprotect("PassW0rd")
                oSheet.Visible = Excel.XlSheetVisibility.xlSheetVisible
                oSheet.Protect("PassW0rd")

Answer : How do I copy a template excel sheet in the same workbook in order to populate the new sheet with data from my database

I am going to let this thread run for another day or so and close it since there is not anyone out there that seems to understand or have the knowledge on how to address my issue.

if you know something about how to fix this, in any way, please share!

Thank you,

Jason

Random Solutions  
 
programming4us programming4us