1
Good morning to all!
I am trying to integrate excel to other software (the EES - Engineering Equation Solver) through a code in vba.
My program copies certain columns of a table, transfers to the other program, performs the calculations, copies the results and pastes in the corresponding columns of my table in excel. The EES help site itself provides an example program for operation, which I am using as a basis.
The problem is that my program returns decimal values and excel is not recognizing the comma of the pasted data! The strange thing is that decimal data copied from excel to EES is interpreted correctly and if I copy and paste the EES data manually in the spreadsheet the number comes with the comma correctly!
My excel is already set to recognize comma as decimal separator, equal to EES. The code follows below:
Private Sub cmdDDE_Click()
Dim ChNumber As Integer
Dim myShell As String
ChNumber = -1
myShell = frmEESDDE.txtApp.Text
On Error Resume Next
'Copy selected rows into clipboard
Range("B2:G1401").Select
Selection.Copy
Shell_R = Shell(myShell, 1)
If Shell_R <> "" Then
'Initiate DDE
ChNumber = Application.DDEInitiate(app:="ees", topic:="")
If ChNumber <> -1 Then
'Open EES
Application.DDEExecute ChannelNumber, "[Open C:\EES\Tablesolve.ees]"
'Paste data
Application.DDEExecute ChannelNumber, "[Paste Parametric 'Table 1' R1 C1]"
'Solve parametrictable
Application.DDEExecute ChannelNumber, "[SOLVETABLE 'TABLE 1' Rows=1..1400]"
'Copy results
Application.DDEExecute ChannelNumber, "[COPY ParametricTable 'Table 1' R1 C7:R1400 C14]"
'Choose separators
Application.DecimalSeparator = ","
Application.ThousandsSeparator = "."
Application.UseSystemSeparators = False
'Paste results from EES into EXCEL
Application.Paste Destination:=Worksheets("Sheet1").Range("H2:O1440")
Application.UseSystemSeparators = True
'Quit EES and Terminate DDE
DDEExecute ChNumber, "QUIT"
Application.DDETerminate ChNumber
Else
MsgBox "Unable to initiate connection to EES", vbExclamation, "EES DDE"
End If
frmEESDDE.Hide
Else
MsgBox "The application, " & myShell & ", was not found", vbExclamation, "EES DDE"
End If
End Sub
PS = Note that I have tried using the command Application.Decimalseparator = "," but it didn’t work. My result of, for example, "15.47" appears in excel as "1.55E+12" or as "1547421377050".
Thanks for your help!
How is your Windows decimal separator? I ask this because you say to use the decimal separator of the operating system (Application.Usesystemseparators = True). If you want to use the decimal separator set by you, then you should leave this property as false, i.e., Application.Usesystemseparators = False. Incidentally, note that you arrow it as false and just below as true.
– cantoni
Yes, Windows is in the configuration "Portuguese brasil" whose default is the comma as decimal separator. Excel and EES automatically follow these settings and I’ve also checked that the two are set to recognize the comma as decimal separator. In the case of the part of the code that defines the separators, I followed the suggestion of this link: http://stackoverflow.com/questions/28105731/pasting-decimal-numbers-in-excel-comma-and-point-decimal-separator In it, use-if Application.Usesystemseparators = False before and after paste back to normal by doing Application.Usesystemseparators = True.
– Mariana
i did not find the Application.Paste method in my Excel (version 2010). Please try the following: Worksheets("Sheet1"). Range("H2"). Pastespecial instead of Application.Paste Destination:=Worksheets("Sheet1"). Range("H2:O1440"). Also, open the Notepad and try Paste to see how the data is coming after running this line (Application.Ddeexecute Channelnumber, "[COPY Parametrictable 'Table 1' R1 C7:R1400 C14]").
– cantoni
Tested replace the command and by Worksheets("Sheet1"). Range("H2"). Pastespecial as you suggested but then the code glue the input variables again instead of pasting the results. The same occurs in the Notepad. To paste in the Notepad I used the commands:
Shell "notepad.exe", vbNormalFocus
SendKeys "^V"
PS= have no mt experience with VBA.– Mariana