Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Change Excels CodeName property
Message
 
À
05/06/2001 17:34:17
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00515421
Message ID:
00516057
Vues:
14
>>I am tring to change the CodeName of an excel WorkSheet.
>>
>>I found this example for VBA on the web, but I am unable to get it to work.
>>
>>Sub RenameCodeName(oWks As Sheet, sNewName As String)
>> oWks.Parent.VBProject.vbComponents(oWks.CodeName).Properties("_CodeName") = sNewName
>>End Sub
>>
>>Example:
>>oExcel = CreateObject("Excel.Application")
>>oExcel.WorkBooks.OPEN("TestFile.xls")
>>*-- File contains a worksheet called "Sheet1"
>>oExcel.sheets("Sheet1").COPY(oExcel.Worksheets("Sheet1"))
>>lcTempCopySheet = "Sheet1 (2)"
>>oExcel.sheets(lcTempCopySheet).NAME = "ReNamedSheet"
>>oExcel.Sheets("ReNamedSheet").SELECT
>>oWks = oExcel.ActiveSheet
>>oWks.Parent.VBProject.vbComponents(oWks.CodeName).Properties("_CodeName") = "ReNamedCode" && generates an error
>>*-- The error that I am getting is Function argument value, type, or count is invalid
>
>Can you post the code as you translated it? Or were you trying to run this exact code in VFP? (hint- VFP doesn't use the Sub keyword)

Erik,
Here is an example of the code

oExcel = CreateObject("Excel.Application")
oExcel.WorkBooks.OPEN("TestFile.xls")
*-- File contains a worksheet called "Sheet1"
oExcel.sheets("Sheet1").COPY(oExcel.Worksheets("Sheet1"))
lcTempCopySheet = "Sheet1 (2)"
oExcel.sheets(lcTempCopySheet).NAME = "ReNamedSheet"
oExcel.sheets("ReNamedSheet").SELECT
*-- oWks = oExcel.ActiveSheet
=RenameCodeName(oExcel.ActiveSheet, "ReNamedCode")
oExcel = .null.

FUNCTION RenameCodeName
LPARAMETERS oWks, sNewName
oWks.Parent.VBProject.vbComponents(oWks.CodeName).Properties("_CodeName") = sNewName
ENDFUNC
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform