Import Data From Other Excel File

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Import data from other Excel file

Dim xls As New Excel.Application

Sub import()
Dim myfile(1) As String

Dim i As Integer
For i = 0 To 1
myfile(i) = "test" & (i + 1) & ".xlsx"
Set myworkbook = openExcel(myfile(i), "C:\Users\Bikuz\Desktop\")
With myworkbook
Sheet1.Cells(i + 1, 1) = .Sheets("sheet1").Cells(1, 1)
End With
myworkbook.Close
Next i

xls.Quit

End Sub

Function openExcel(filename As String, path As String) As Excel.Workbook


Set openExcel = xls.Workbooks.Open(path + filename)
End Function

Restrict Alphabets
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Asc("-")
If InStr(1, TextBox1.Text, "-") > 0 Or TextBox1.SelStart > 0 Then
KeyAscii = 0
End If
Case Asc(".")
If InStr(1, Me.TextBox1.Text, ".") > 0 Then
KeyAscii = 0
End If
Case Else
KeyAscii = 0
End Select
End Sub

Calculate Bearing
Private Function getBearing(FromptX As Double, FromptY As Double, ToptX As
Double, ToptY As Double) As Double
Dim del_x As Double, del_y As Double
Dim pi As Double
pi = 22 / 7

del_x = ToptX - FromptX


del_y = ToptY - FromptY

If del_x = 0 Then
bear = 90
Else

bear = Math.Atn(Math.Abs(del_y) / Math.Abs(del_x))


bear = 180 * bear / pi
End If

If (del_x >= 0 & del_y >= 0) Then


bear = 90 - bear
ElseIf (del_x >= 0 And del_y < 0) Then
bear = bear + 90
ElseIf (del_x < 0 & del_y < 0) Then
bear = 270 - bear
ElseIf (del_x < 0 & del_y >= 0) Then
bear = bear + 270
End If
getBearing = bear

End Function

You might also like