Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 01-24-2013, 03:31 AM
eldivi eldivi is offline
Registered User
 
Join Date: Jan 2013
Posts: 4
Copy sheet to same workbook

Hi, I want to copy an excel sheet in the same workbook
Reply With Quote
  #2  
Old 01-24-2013, 09:01 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,153
Hi eldivi,

I am not sure how that involves one of our products.

Do you have a script you are running from SecureCRT that is already working with an Excel spreadsheet?

Please explain your objective in further detail.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 01-25-2013, 02:37 AM
eldivi eldivi is offline
Registered User
 
Join Date: Jan 2013
Posts: 4
I want to access an excel sheet, copy it and then edit it, so I do not modify the original sheet.

This is my code:

If SheetExists(wb, strSheetName) Then
set ws = wb.Sheets(strSheetName)
Else
MsgBox("There is no template, create it manually")
exit function
end if

ws.Activate

ws.Cells(5, 2).Value = '...'
....

app.Visible = True
If MsgBox("Save Changes to workbook?", vbYesNo) <> vbYes Then
wb.Close False
Else
wb.SaveAs "Z:\CGP\Tareas\Pruebas CCM\"& horaactual &".xls"
Set oExec = CreateObject("WScript.Shell")
oExec.Run "Z:\CGP\Tareas\Pruebas CCM\"& horaactual &".xls"
wb.Close True
End If

I would like to always work in the same book without deleting the original sheet.
Reply With Quote
  #4  
Old 01-25-2013, 09:49 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,153
Hello eldivi,

These forums are specific to VanDyke Software products. If you are using a VanDyke Software product, which one is it, and how does it relate to your Excel project?

If your question is regarding Excel, you may want to look for an appropriate Microsoft resource.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 01-28-2013, 01:44 AM
eldivi eldivi is offline
Registered User
 
Join Date: Jan 2013
Posts: 4
I use SecureCRT. I go into a server and get some data, then I want them stored in a excel sheet.

crt.Screen.Synchronous = True
crt.session.Connect("/ssh2 /L "&usuario&" /PASSWORD "&clave&" /C 3DES /M MD5 " & ip3)

crt.Screen.Send "show environment fans" & VbCr
crt.Screen.Send "show environment power-supply" & VbCr
...
Reply With Quote
  #6  
Old 01-28-2013, 11:54 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,153
Hi Eldivi,

You stated the original objective as copying a worksheet, so I am not sure if your latest post is explanatory or also a request.

We do have some script examples that show how to work with Excel, they have been posted (attached) to many threads in the forums previously.

In the near future, we will probably post an Excel example in the main script sticky here to be certain the latest version is available.

To specifically add or copy a worksheet, see the URLs below. They explain the Add/Copy methods available to the Worksheet object in Excel.

Add method:
http://msdn.microsoft.com/en-us/libr...ffice.14).aspx

Copy method:
http://msdn.microsoft.com/en-us/libr...ffice.14).aspx

As a note, you might have just been providing the code in your last post as an example, but you should keep in mind the advice from the scripting manual (section 4.2), available on our website here, that there should be a WaitForString() following each Send() command.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 01-29-2013, 05:22 AM
eldivi eldivi is offline
Registered User
 
Join Date: Jan 2013
Posts: 4
Hi, this is the code that I have developed, it works.

wb.Sheets(strSheetName).Copy wb.Sheets(1)
wb.Sheets(strSheetName).Name = strSheetNameNew
wb.Sheets(strSheetName & " (2)").Name = strSheetName 'I set the original name
Set ws = wb.Sheets(strSheetNameNew)

ws.Cells(5,i + 2).Value = resultado
...

If MsgBox("¿Desea guardar los cambios en Formulario Pruebas CCM.xls?", vbYesNo) <> vbYes Then
wb.Close False
Else
wb.Close True

End If

Thanks!!!
Reply With Quote
  #8  
Old 01-29-2013, 09:41 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,153
Hi eldivi,

Thanks for posting. I am glad to hear you were able to accomplish your objective!
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 12:36 AM.