Wednesday, December 27, 2017

Automating searching mails in outlook with a particular word in the subject,copy the mail message and the sender's mail address in an existing excel file,VBA Teacher Sourav,Kolkata 09748184075


Sub CloseOutlook()
Dim OL As Object
On Error Resume Next
Set OL = GetObject(, "Outlook.Application")
On Error GoTo 0
If OL Is Nothing Then
'MsgBox "Outlook is not running!"
Else
OL.Quit
End If
End Sub


 Sub Search_Inbox()
 'Optimize Macro Speed
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  Application.Calculation = xlCalculationManual
  Dim wb As Workbook
 'Trying to close outlook first

 CloseOutlook
 'Trying to close the target excel file

    'now let's see if the workbook where the data to be pasted is open or not
       
         Dim status As Boolean

         status = IsWorkBookOpen("C:\Users\sourav\Desktop\data.xlsm")
         If status = True Then
         Workbooks("data.xlsm").Close SaveChanges:=True
        
         End If
       

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myitems As Outlook.Items
Dim myItem As Object
Dim Found As Boolean
Dim atmt As Outlook.Attachment
Dim MyAr() As String
Dim address As String
Dim message As String


Dim ws As Worksheet
Dim aCell As Range, Rng As Range
Dim col As Long, lRow As Long
Dim colName As String
On Error Resume Next

Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myitems = myInbox.Items
Found = False

For Each myItem In myitems
    If myItem.Class = olMail Then
        If InStr(1, myItem.Subject, "macro") > 0 Then
            'MsgBox ("Found")
            For Each atmt In myItem.Attachments

                If atmt.FileName = "macro.txt" Then
                    atmt.SaveAsFile "D:\" & atmt.FileName
                    'MsgBox (myItem.SenderEmailAddress)
                    'saving the mail body in an array
               
                    MyAr = Split(myItem.Body, vbCrLf)

                    For i = LBound(MyAr) To UBound(MyAr)
                        '~~> This will give you the contents of your email
                        '~~> on separate lines
                        'MsgBox (MyAr(i))
                        If MyAr(i) <> "" Then
                        message = message + MyAr(i)
                        End If
   
   
                    Next i

                    'Now trying to write the message and the sender address in an existing excel file

                    'First trying to close the file if it is already open
                    On Error Resume Next

                    Workbooks("data.xlsm").Close SaveChanges:=True

                    'now trying to open the file

                    Set wb = Workbooks.Open("C:\Users\sourav\Desktop\data.xlsm")
                    'now finding the spicific column with some word or words
                    Set ws = wb.Sheets("Sheet2")

                    With ws
                        Set aCell = .Range("A1:P1").Find(What:="Mail*", LookIn:=xlValues, LookAt:=xlWhole, _
                        MatchCase:=False, SearchFormat:=False)
                        If Not aCell Is Nothing Then
                            col = aCell.Column
                            colName = Split(.Cells(, col).address, "$")(1)
                            'MsgBox (colName)

                            lRow = .Range(colName & .Rows.count).End(xlUp).Row
                            'MsgBox (lRow)
           
                            '~~> This is your range
                            'Set Rng = .Range(colName & "8:" & colName & lRow)

                            'MsgBox (Rng.address)
                            '~~> If not found
       
                            'Now find the blank cell in the column found earlier
                            Set Rng = .Range(colName & lRow)
                            Rng.Select
       
                             Range(Selection.End(xlDown)).Select
                             ActiveCell.Offset(1, 0).Select
                            
                           
                            ActiveCell.Value = myItem.SenderEmailAddress
                            If ActiveCell.Offset(0, 1) = "" Then
                                ActiveCell.Offset(0, 1).Value = message
                            End If
                            ws.Columns.AutoFit
                        Else
                            ' MsgBox "Mail Not Found"
                        End If
                        End With
                        On Error Resume Next
                        wb.Close SaveChanges:=True
                        Set wb = Nothing
                        Set ws = Nothing
                       
                        'MsgBox ("Done")

                End If


                message = ""
            Next
                Found = True
        End If
    End If
Next myItem

'If the subject isn't found:
If Not Found Then
   ' NoResults.Show
   MsgBox ("Task Failed")
  
End If

myOlApp.Quit
Set myOlApp = Nothing


'Reset Macro Optimization Settings
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
End Sub

Monday, December 25, 2017

Search mail in outlook with a particular word in the subject and read the message in the mail line by lines using VBA,VBA Teacher Sourav,Kolkata 09748184075


Sub CloseOutlook()
Dim OL As Object
On Error Resume Next
Set OL = GetObject(, "Outlook.Application")
On Error GoTo 0
If OL Is Nothing Then
MsgBox "Outlook is not running!"
Else
OL.Quit
End If
End Sub


 Sub Search_Inbox()
 'Trying to close outlook first

 CloseOutlook


Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myitems As Outlook.Items
Dim myItem As Object
Dim Found As Boolean
Dim atmt As Outlook.Attachment
Dim MyAr() As String
On Error Resume Next

Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderSentMail)
Set myitems = myInbox.Items
Found = False

For Each myItem In myitems
    If myItem.Class = olMail Then
        If InStr(1, myItem.Subject, "macro") > 0 Then
            'MsgBox ("Found")
            For Each atmt In myItem.Attachments

If atmt.FileName = "macro.txt" Then
atmt.SaveAsFile "D:\" & atmt.FileName

MyAr = Split(myItem.Body, vbCrLf)

For i = LBound(MyAr) To UBound(MyAr)
    '~~> This will give you the contents of your email
    '~~> on separate lines
    MsgBox (MyAr(i))
Next i
MsgBox ("Done")

End If



Next
            Found = True
        End If
    End If
Next myItem

'If the subject isn't found:
If Not Found Then
   ' NoResults.Show
End If

myOlApp.Quit
Set myOlApp = Nothing

End Sub

Saturday, December 23, 2017

find mail based on words in subject in outlook and save their attachments,VBA Teacher Sourav,Kolkata 09748184075

Sub Search_Inbox()

Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myitems As Outlook.Items
Dim myitem As Object
Dim Found As Boolean
Dim atmt As Outlook.Attachment
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myitems = myInbox.Items
Found = False

For Each myitem In myitems
    If myitem.Class = olMail Then
        If InStr(1, myitem.Subject, "macro") > 0 Then
            'MsgBox ("Found")
            For Each atmt In myitem.Attachments

If atmt.Filename = "macro.txt" Then
atmt.SaveAsFile "F:\" & atmt.Filename
End If



Next
            Found = True
        End If
    End If
Next myitem

'If the subject isn't found:
If Not Found Then
    NoResults.Show
End If

myOlApp.Quit
Set myOlApp = Nothing

End Sub


Source:Stackoverflow

Friday, December 22, 2017

Open a workbook in a directory,filter the data based on criteria,copy the filtered data in a different workbook,automating daily office work using VBA,VBA teacher Sourav,Kolkata 09748184075

Option Explicit




Sub LoopAllExcelFilesInFolder()

'PURPOSE: To loop through all Excel files in a user specified folder and perform a set task on them
'SOURCE: www.TheSpreadsheetGuru.com

Dim wb As Workbook
Dim myPath As String
Dim myFile As String
Dim myExtension As String
Dim FldrPicker As FileDialog
Dim N As Long
'First trying to close the file if it is already open
On Error Resume Next

Workbooks("data.xlsm").Close SaveChanges:=True

'Optimize Macro Speed
  Application.ScreenUpdating = False
  Application.EnableEvents = False
  Application.Calculation = xlCalculationManual

'Retrieve Target Folder Path From User
  Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)

    With FldrPicker
      .Title = "Select A Target Folder"
      .AllowMultiSelect = False
        If .Show <> -1 Then GoTo NextCode
        myPath = .SelectedItems(1) & "\"
    End With

'In Case of Cancel
NextCode:
  myPath = myPath
  If myPath = "" Then GoTo ResetSettings

'Target File Extension (must include wildcard "*")
  myExtension = "data.xls*"

'Target Path with Ending Extention
  myFile = Dir(myPath & myExtension)

'Loop through each Excel file in folder
  Do While myFile <> ""
    'Set variable equal to opened workbook
      Set wb = Workbooks.Open(FileName:=myPath & myFile)
   
    'Ensure Workbook has opened before moving on to next line of code
      DoEvents
   
    'Change First Worksheet's Background Fill Blue
      wb.Worksheets(1).Range("A1:Z1").Interior.Color = RGB(51, 98, 174)
     
      'Let's try the autofiltering
        ActiveWorkbook.Sheets("Sheet1").Activate
     
      
        On Error Resume Next
   
        ActiveWorkbook.ActiveSheet.ShowAllData
  
        ActiveSheet.Range("A1").AutoFilter Field:=35, Criteria1:= _
        "August 2015"
       
       
     
        N = Range("AI" & Rows.count).End(xlUp).Row
        Range("AI2:AI" & N).Select
        Selection.Copy
    'Save and Close Workbook
      wb.Close SaveChanges:=True
     
        'now let's see if the workbook where the filtered data to be pasted is open or not
       
         Dim status As Boolean

         status = IsWorkBookOpen("C:\Users\sourav\Desktop\filter_final_RD.xlsx")
         If status = False Then

         Workbooks("C:\Users\sourav\Desktop\filter_final_RD.xlsx").Open
         End If
        
         Workbooks("C:\Users\sourav\Desktop\filter_final_RD.xlsx").Activate
         ActiveWorkbook.Sheets("DATABASE").Select
         Range("AJ3").Select
         ActiveSheet.Paste
        
       
         Application.CutCopyMode = False
         wb.Activate
        
        

     
    'Ensure Workbook has closed before moving on to next line of code
      DoEvents

    'Get next file name
      myFile = Dir
  Loop

'Let/'s try the filtering

'Message Box when tasks are completed
  MsgBox "Task Complete!"

 Workbooks("C:\Users\sourav\Desktop\filter_final_RD.xlsx").Activate
         ActiveWorkbook.Sheets("DATABASE").Select
ActiveWorkbook.Save

ResetSettings:
  'Reset Macro Optimization Settings
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True



End Sub

Function IsWorkBookOpen(FileName As String)
    Dim ff As Long, ErrNo As Long

    On Error Resume Next
    ff = FreeFile()
    Open FileName For Input Lock Read As #ff
    Close ff
    ErrNo = Err
    On Error GoTo 0

    Select Case ErrNo
    Case 0:    IsWorkBookOpen = False
    Case 70:   IsWorkBookOpen = True
    Case Else: Error ErrNo
    End Select
End Function

Saturday, November 18, 2017

Download certain indexed videos from a playlist in youtube using youtube-dl,Computer Teacher Sourav,Kolkata 09748184075



Suppose there is a playlist in youtube and you want to download videos indexed at 7 to 9(the indexing starts at 1),the command should be

pip -install youtube-dl

traverse to the directory in command line where you want to save the files  



youtube-dl --playlist-start=7 --playlist-end=9 -ci 

https://www.youtube.com/playlist?list=PLQVvvaa0QuDc2QjQOkZ4rtLYZVll_sZFZ


Sunday, November 5, 2017

Windows Resource Protection found corrupt files but was unable to fix some of them fixed,Computer Teacher Sourav,Kolkata 09748184075

when running sfc /scannow i am presented with an error called

" Windows Resource Protection found corrupt files but was unable to fix some of them"

The solution is

from an elevated command prompt run


Dism /Online /Cleanup-Image /RestoreHealth

if successful then run

sfc /scannow 


again

Saturday, October 21, 2017

Dropdown with values from different sheet and showing the first element of the list in the dropdown cell using vba

Sub autofill1()
'
' Macro1 Macro
'

'
'For C column autifilling

Sheets("Service Catalogue").Select
 Dim inputRange As Range

    Range("C6").Select
   
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Services"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
       
    End With
    Dim namedrange As Range
    Set namedrange = Range("Services")
    ActiveCell.Value = (namedrange.cells(1, 1).Value)
   
   
    Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
   
     Dim dd As DropDown

   
  'For D column autofilling
 
    Sheets("Service Catalogue").Select

    Range("D6").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=INDIRECT(C6)"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
  
  


   
 Set inputRange = Evaluate(Range("D6").Validation.Formula1)
  Range("D6").Select
  ActiveCell.Value = inputRange(1)
  Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
   'For E column autofilling
  
    Sheets("Service Catalogue").Select

    Range("E6").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=INDIRECT(D6)"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
  
    Set inputRange = Evaluate(Range("E6").Validation.Formula1)
  Range("E6").Select
  ActiveCell.Value = inputRange(1)
  Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
   'For F column autofilling
  
   Sheets("Service Catalogue").Select

    Range("F6").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=INDIRECT(E6)"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
  
  
    Set inputRange = Evaluate(Range("F6").Validation.Formula1)
  Range("F6").Select
  ActiveCell.Value = inputRange(1)
  Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
       
         'For G column autofilling
  
   Sheets("Service Catalogue").Select

    Range("G6").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Selection"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
  
  
    Set inputRange = Evaluate(Range("G6").Validation.Formula1)
  Range("G6").Select
  ActiveCell.Value = inputRange(1)
  Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
       
       
          
         'For H column autofilling
  
   Sheets("Service Catalogue").Select

    Range("H6").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=INDIRECT(G6)"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
  
  
    Set inputRange = Evaluate(Range("H6").Validation.Formula1)
  Range("H6").Select
  ActiveCell.Value = inputRange(1)
  Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
       
          'For I column autofilling
  
   Sheets("Service Catalogue").Select

    Range("I6").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Infra"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
  
  
    Set inputRange = Evaluate(Range("I6").Validation.Formula1)
  Range("I6").Select
  ActiveCell.Value = inputRange(1)
  Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
       
         'For I column autofilling
  
   Sheets("Service Catalogue").Select

    Range("J6").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=SelectionTS"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
    Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
  
  
    Set inputRange = Evaluate(Range("J6").Validation.Formula1)
  Range("J6").Select
  ActiveCell.Value = inputRange(1)
  Selection.AutoFill Destination:=ActiveCell.Range("A1:A18"), Type:= _
        xlFillDefault
       
       
       
End Sub

Friday, October 20, 2017

If Column G entered is “NO”, Colum “H” will be protected. If Column G entered is “YES”, column H will be unprotected scenario in vba,VBA Teacher Sourav,Kolkata 09748184075


Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
ActiveWorkbook.Save
Sheets("Sheet1").Select
ActiveSheet.Unprotect Password:="0000"
Dim cells As Range
Set cells = ActiveSheet.Range("H:H")


cells.Locked = True
ActiveSheet.Protect Password:="0000"

End Sub

Private Sub Workbook_Open()
Sheets("Sheet1").Select



Application.Calculation = xlManual

Call calldropdown

Sheets("Sheet1").Select
'ActiveSheet.Unprotect Password:="0000"
'Dim cells As Range
'Set cells = ActiveSheet.Range("H:H")
'ActiveSheet.cells.Select

'cells.Locked = True

ActiveSheet.Protect Password:="0000"

End Sub




Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Dim inputRange As Range


Set ws = Worksheets("Sheet1")
'tell this sub to unprotect only these cells
Set inputRange = Range("G1,I1,M1,O1")


' If the selected cell is not in the range keep the sheet locked
If Intersect(Target, inputRange) Is Nothing Then
'else unprotect the sheet by providing password
'(same as the one that was used to protect this sheet)
Else

    ws.Unprotect Password:="0000"
    Target.Locked = False
    ws.Protect Password:="0000"

End If
End Sub


Sub test1()
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim cells As Range
Dim workingsheet As Worksheet
Set workingsheet = Worksheets("Sheet1")
Set cells = workingsheet.Range("H:H")

Sheets("Sheet1").Activate

Range("G1").Select
If ActiveCell.Value = "YES" Then
'MsgBox ("Hello")

workingsheet.Unprotect Password:="0000"
cells.Locked = False
'cells.Value = "Got it"
 workingsheet.Protect Password:="0000"
 Else
 workingsheet.Unprotect Password:="0000"
cells.Locked = True

'cells.Value = "Got it"
 workingsheet.Protect Password:="0000"
 End If

Application.ScreenUpdating = True
Application.EnableEvents = True



End Sub


Sub dropdown(pos As String, ByRef valdropdown() As String)
'
' Macro1 Macro
'

'


Set ws = Worksheets("Sheet1")
ws.Select

  
   
Range(pos).Select
ws.Unprotect Password:="0000"
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:=Join(valdropdown, ",")
       
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
   
   
    ws.Protect Password:="0000"
End Sub

Sub testarr()
 Dim valG1() As String
 valG1 = Split("A, B, C", ",")

 testarr2 valG1

End Sub

Sub testarr2(ByRef valG1() As String)
MsgBox (UBound(valG1))

End Sub


Sub calldropdown()

Sheets("Sheet1").Select

Dim valG1() As String
 valG1 = Split("YES, NO", ",")
 Dim valI1() As String
 valI1 = Split("L, M, N", ",")
 Dim valM1() As String
 valM1 = Split("X, Y, Z", ",")
 Dim valO1() As String
 valO1 = Split("1, 2, 3", ",")



Call dropdown("G1", valG1)

Call dropdown("I1", valI1)
Call dropdown("M1", valM1)
Call dropdown("O1", valO1)



End Sub



Tuesday, October 17, 2017

conditionally unlock a cell using vba,vba teacher sourav,Kolkata 09748184075

Sub test1()
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim cells As Range
Dim workingsheet As Worksheet
Set workingsheet = Worksheets("Sheet1")
Set cells = workingsheet.Range("G5")

Sheets("Sheet1").Activate

Range("G1").Select
If ActiveCell.Value = "A" Then
workingsheet.Unprotect Password:="0000"
cells.Locked = False
cells.Value = "Got it"
 workingsheet.Protect Password:="0000"
 Else

 End If

Application.ScreenUpdating = True
Application.EnableEvents = True



End Sub

Monday, October 16, 2017

Excel dropdowns from arrays in a protected worksheet where only the cells fixed for dropdown is allowed to change in VBA,VBA Teacher Sourav,Kolkata 09748184075

Private Sub Workbook_Open()
Sheets("Sheet1").Select



Application.Calculation = xlManual

Call calldropdown

On Error Resume Next
ActiveSheet.Protect Password:="0000"



End Sub




Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim ws As Worksheet
Dim inputRange As Range


Set ws = Worksheets("Sheet1")
'tell this sub to unprotect only these cells
Set inputRange = Range("G1,I1,M1,O1")


' If the selected cell is not in the range keep the sheet locked
If Intersect(Target, inputRange) Is Nothing Then
'else unprotect the sheet by providing password
'(same as the one that was used to protect this sheet)
Else

    ws.Unprotect Password:="0000"
    Target.Locked = False
    ws.Protect Password:="0000"

End If
End Sub


Sub dropdown(pos As String, ByRef valdropdown() As String)
'
' Macro1 Macro
'

'


Set ws = Worksheets("Sheet1")
ws.Select

  
   
Range(pos).Select
ws.Unprotect Password:="0000"
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:=Join(valdropdown, ",")
       
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
   
   
    ws.Protect Password:="0000"
End Sub

Sub testarr()
 Dim valG1() As String
 valG1 = Split("A, B, C", ",")

 testarr2 valG1

End Sub

Sub testarr2(ByRef valG1() As String)
MsgBox (UBound(valG1))

End Sub


Sub calldropdown()

Sheets("Sheet1").Select

Dim valG1() As String
 valG1 = Split("A, B, C", ",")
 Dim valI1() As String
 valI1 = Split("L, M, N", ",")
 Dim valM1() As String
 valM1 = Split("X, Y, Z", ",")
 Dim valO1() As String
 valO1 = Split("1, 2, 3", ",")



Call dropdown("G1", valG1)

Call dropdown("I1", valI1)
Call dropdown("M1", valM1)
Call dropdown("O1", valO1)



End Sub



Reset your vba project password,VBA Teacher Sourav,Kolkata 09748184075


https://www.youtube.com/watch?v=Lpt-DbXPPJc



Follow the steps in this video

Tuesday, August 29, 2017

transaction-check-error-in-installing-vim solved,linux faculty Sourav,Kolkata 09748184075

yum update vim-minimal

yum install vim


source:https://unix.stackexchange.com/questions/119310/transaction-check-error-in-installing-vim

Enable and disable hyper v on windows 8.1 so that hyper v,visual studio 2013 phone sdk and vmware can be used properly ,IT Faculty Sourav Bhattacharya,Kolkata 09748184075

From an elevated command prompt:

bcdedit /set hypervisorlaunchtype off
to disable hypervisor, and:

bcdedit /set hypervisorlaunchtype auto
to reenable it (default value).

Of course it still requires restart.

Source:https://superuser.com/questions/540055/convenient-way-to-enable-disable-hyper-v-in-windows-8

DVD Drive not detected in windows 8.1 solved,IT Faculty Sourav Bhattacharya,Kolkata 09748184075

For the these steps solved the issue

To remove and reinstall IDE/ATAPI driver, follow these steps:

From Start, search for Device Manager. Open Device Manager from the search results, and select the View menu. Choose Show Hidden Devices.
Expand IDE/ATAPI Controllers, and then:
Select and right-click ATA Channel 0, and then click Uninstall
Select and right-click ATA Channel 1, and then click Uninstall
Select and right-click Standard Dual Channel PCI IDE Controller, and then click Uninstall
If there are additional entries, right-click them and then choose Uninstall
Reboot the device.
After the computer restarts, the drivers will be automatically installed.

If your problem is not solved, try the next method.

source:https://support.microsoft.com/en-in/help/314060/your-cd-or-dvd-drive-is-not-recognized-by-windows-or-other-programs




Tuesday, May 16, 2017

Install oracle 11g on Scientific Linux 6,Oracle Teacher Sourav,Kolkata 09748184075

installing oracle 11g on scientific linux 6

as root

yum -y install openssh-server

service sshd start

chkconfig sshd on

yum -y install nano

nano /etc/group

make the line look like this

wheel:x:10:root,sourav

save and exit

nano /etc/pam.d/su

uncomment the following two lines to make sourav as powerful 

as root

# Uncomment the following line to implicitly trust users in 

the "wheel" group.

auth            sufficient      pam_wheel.so trust use_uid

# Uncomment the following line to require a user to be in the 

"wheel" group.

auth            required        pam_wheel.so use_uid


save and exit


stop and disable iptables by

/etc/rc.d/init.d/iptables stop 

chkconfig iptables off 


stop and disable ip6tables by

/etc/rc.d/init.d/ip6tables stop 

chkconfig ip6tables off

disable selinux

by 

nano /etc/sysconfig/selinux

change the line 

SELINUX=enforcing to

SELINUX=disabled

save and exit

set the hostname to oracle.sourav by

nano /etc/hosts

127.0.0.1       oracle.sourav   sourav  localhost.localdomain 

localhost
::1             localhost6.localdomain6 localhost6

save and exit

nano /etc/sysconfig/network

make the file look like this

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=oracle.sourav


save and exit

i am using dhcp so my network card file should look like this

 nano /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0

BOOTPROTO=dhcp

ONBOOT=yes

NM_CONTROLLED=no

PEERDNS=no

DNS1=8.8.8.8

DNS2=4.2.2.2


save and exit

to set the dns

  nano /etc/resolv.conf

# Generatedby NetworkManager
search google.com
nameserver 8.8.8.8
nameserver 4.2.2.2


save and exit

to stop the NetworkManager

 service NetworkMnager stop

to make sure NetworkManager won't start at the next reboot

 chkconfig NetworkManager off


to restart the network

/etc/rc.d/init.d/network restart 

 chkconfig network on 


let's reboot and let's see if everything going just fine

ok everything is fine

one more thing 

let us disable ipv6 as it is not needed here

 echo "install ipv6 /bin/true" > /etc/modprobe.d/disable-

ipv6.conf

ok everything is set 

now let's try to install oracle's dependencies 

yum -y install binutils compat-libstdc++-33 elfutils-libelf 

elfutils-libelf-devel glibc glibc-common glibc-devel gcc 

gcc-c++ libaio libaio-devel libgcc libstdc++ libstdc++-devel 

make sysstat unixODBC unixODBC-devel 

after installing now let's set some kernel parameters

nano /etc/sysctl.conf 

comment out those three lines

#net.bridge.bridge-nf-call-ip6tables = 0
#net.bridge.bridge-nf-call-iptables = 0
#net.bridge.bridge-nf-call-arptables = 0


and also comment out 

#kernel.shmmax = 4294967295


and



#kernel.shmall = 268435456


at the end add this section

net.ipv4.ip_local_port_range = 9000 65500
fs.file-max =65536
kernel.shmall = 10523004
kernel.shmmax = 6465333657
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default=262144
net.core.wmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_max=1048576 



save and exit

using the sysctl -p check out the output

it should be like

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.ip_local_port_range = 9000 65500
fs.file-max = 65536
kernel.shmall = 10523004
kernel.shmmax = 6465333657
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576


ok now let's create an user for oracle

groupadd -g 200 oinstall 

groupadd -g 201 dba 

useradd -u 440 -g oinstall -G dba -d /usr/oracle oracle 

passwd oracle

set the password

nano /etc/pam.d/login


add this line

session   required   pam_limits.so

before the line

session    optional     pam_keyinit.so force revoke

save and exit

nano /etc/security/limits.conf 

add these lines at the end


before # End of file

oracle   soft   nproc   2047
oracle   hard   nproc   16384
oracle   soft   nofile   1024
oracle   hard   nofile   65536


save and exit

nano /etc/profile

at the end add these lines

if [ $USER = "oracle" ]; then
       if [ $SHELL = "/bin/ksh" ]; then
            ulimit -p 16384
            ulimit -n 65536
       else
            ulimit -u 16384 -n 65536
       fi
 fi


save and exit

now switch to the user oracle

su oracle

cd ~

chmod 755 /usr/oracle 


mkdir /usr/oracle/app 


chmod 775 /usr/oracle/app 

mkdir /usr/oracle/oradata 

chmod 775 /usr/oracle/oradata

nano ~/.bash_profile 

at the end add these lines

umask 022
export ORACLE_BASE=/usr/oracle/app

save and exit

mkdir tmp

using winscp copy the oracle 11g installation files in the 

target machine

ok before trying to install oracle as root you need

to execute the command xhost + in the target machine

 unzip linux_11gR2_database_1of2.zip

 unzip linux_11gR2_database_2of2.zip

Now to avoid pdksh error

go to

/usr/oracle/tmp/database/stage/cvu/cv/admin

Edit cvu_config and change the following line 

CV_ASSUME_DISTID=OEL4 to CV_ASSUME_DISTID=OEL6

save and exit

source://https://unix.stackexchange.com/questions/29554/pdksh

-missing-from-rhel-6-and-centos-6


now

./database/runInstaller  as oracle

you will be presented with an error 

environment does not meet minimum requirements error

probably a bug but i still tried installing java and some 

more

steps but the same error shows up,so i ignored it and

went on

abiding by the default settings 

now when asked 

run this script 
/usr/oracle/oraInventory/orainstRoot.sh 
as root

and 

 /usr/oracle/app/product/11.2.0/dbhome_1/root.sh 

as root

and press enter for defaults

after it's done press ok

the installation should complete successfully
nano ~/.bash_profile 

export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
 export PATH=$PATH:$ORACLE_HOME/bin



source ~/.bash_profile 

rm -rf tmp 


source:https://www.server-world.info/en/note?os=Scientific_Linux_6&p=oracle11g&f=2

Wednesday, May 10, 2017

using dd command on ubuntu 16 to create iso from dvd,Sourav Bhattacharya,RHCE Faculty,Kolkata 09748184075

First check the block size and volume size using this command

isoinfo -d -i /dev/cdrom | grep -i -E 'block size|volume size'

then

dd if=/dev/cdrom of=/home/sourav/centos.iso bs=block size found from previous command 

 count=volume size found from previous command

source://https://www.thomas-krenn.com/en/wiki/Create_an_ISO_Image_from_a_source_CD_or_DVD_under_Linux

Saturday, March 25, 2017

Tuesday, March 7, 2017

from a list of companies calculate for each company the logarithmic daily return using yahoo finance and vba,vba teacher sourav,kolkata 09748184075




Option Explicit

Private Sub test_portfolio()
Application.DisplayAlerts = False
On Error Resume Next
Workbooks("table.csv").Close
Workbooks("Part3.xlsm").Activate
   Dim Symbol As String
   Dim StartDate As Date
   Dim EndDate As Date
   
   
   
   Dim StartDay As Integer
   Dim StartMonth As Integer
   Dim StartYear As Integer
   Dim EndDay As Integer
   Dim EndMonth As Integer
   Dim tempdateval As Date
   Dim previousclosingrate As Date
   
   Dim EndYear As Integer
   Dim closingrate As Double
   
   Dim URL As String
   Dim temppos As String
   
  Sheets("Portfolio").Select
  Range("A2").Select
  
   temppos = Replace(ActiveCell.Address, "$", "")
   Range(temppos).Select
   While ActiveCell.Value <> ""
   temppos = Replace(ActiveCell.Address, "$", "")
   tempdateval = CDate(ActiveCell.Offset(0, 3).Value)
   
   
     Symbol = ActiveCell.Value
     ActiveCell.Offset(0, 3).Select
     
     
     

     StartDate = CDate(ActiveCell.Value)
     
     EndDate = CDate(ActiveCell.Value)
     
     
On Error GoTo 0
'StartDate = CDate(StartDate - 1)

     StartDay = Day(StartDate)
     
     StartMonth = Month(StartDate) - 1
     
     
     StartYear = Year(StartDate)
     
     EndDay = Day(EndDate)
     
     
     EndMonth = Month(EndDate) - 1
          
     EndYear = Year(EndDate)

     URL = "http://real-chart.finance.yahoo.com/table.csv?s=" _
     & Symbol & "&d=" & EndMonth & "&e=" & EndDay & "&f=" & EndYear _
     & "&g=d&a=" & StartMonth & "&b=" & StartDay & "&c=" _
     & StartYear & "&ignore=.csv"
     
     
    ' MsgBox URL
     On Error Resume Next
     
     Workbooks.Open (URL)
       If Err.Number <> 0 Then
       GoTo comingback
       Else
       
     Cells(1, 1).CurrentRegion.Copy
     
     'Workbooks("Assets.xlsm").Activate
     
     Sheets.Add After:=Sheets(Sheets.Count)

     ActiveSheet.Name = Symbol

     ActiveSheet.Paste

     Columns(1).AutoFit
Application.CutCopyMode = False

  Workbooks("table.csv").Activate
  
  Range("E2").Select
  Selection.Copy
  Workbooks("Part3.xlsm").Activate
  Sheets("Portfolio").Select
  Range(temppos).Select
  ActiveCell.Offset(0, 4).Select
  
  
      Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   
closingrate = CDbl(ActiveCell.Value)
ActiveCell.Value = 1

ActiveCell.Value = closingrate * (ActiveCell.Offset(0, -2).Value)
ActiveCell.Select
Selection.NumberFormat = "0.00;[Red]0.00"

Workbooks("table.csv").Activate
On Error Resume Next
ActiveWorkbook.Close
End If
 Call lastclosingrate(temppos, closingrate)

comingback:

Workbooks("Part3.xlsm").Activate
Range(temppos).Select
ActiveCell.Offset(1, 0).Select
temppos = Replace(ActiveCell.Address, "$", "")

Wend

Application.DisplayAlerts = True

End Sub

Sub lastclosingrate(ByVal temppos As String, ByVal closingratefirst As Double)

On Error Resume Next
Workbooks("table.csv").Close
Workbooks("Part3.xlsm").Activate
   Dim Symbol As String
   Dim StartDate As Date
   Dim EndDate As Date
   
   
   
   Dim StartDay As Integer
   Dim StartMonth As Integer
   Dim StartYear As Integer
   Dim EndDay As Integer
   Dim EndMonth As Integer
   Dim tempdateval As Date
   Dim previousclosingrate As Date
   
   Dim EndYear As Integer
   Dim closingratesecond As Double
   
   Dim URL As String
   'Dim temppos As String
   
  Sheets("Portfolio").Select
  
   Range(temppos).Select
  
   tempdateval = CDate(ActiveCell.Offset(0, 3).Value)
   
   
     Symbol = ActiveCell.Value
     ActiveCell.Offset(0, 3).Select
     
     
     

     StartDate = CDate(ActiveCell.Value) - 1
     
     EndDate = CDate(ActiveCell.Value) - 1
     
     
     
On Error GoTo 0
'StartDate = CDate(StartDate - 1)

     StartDay = Day(StartDate)
     
     StartMonth = Month(StartDate) - 1
     
     
     StartYear = Year(StartDate)
     
     EndDay = Day(EndDate)
     
     
     EndMonth = Month(EndDate) - 1
          
     EndYear = Year(EndDate)

     URL = "http://real-chart.finance.yahoo.com/table.csv?s=" _
     & Symbol & "&d=" & EndMonth & "&e=" & EndDay & "&f=" & EndYear _
     & "&g=d&a=" & StartMonth & "&b=" & StartDay & "&c=" _
     & StartYear & "&ignore=.csv"
     
     
    ' MsgBox UR
     
     Workbooks.Open (URL)
       If Err.Number <> 0 Then
       GoTo comingback
       Else
       
     Cells(1, 1).CurrentRegion.Copy
     
     'Workbooks("Assets.xlsm").Activate
     
     Sheets.Add After:=Sheets(Sheets.Count)

     ActiveSheet.Name = Symbol

     ActiveSheet.Paste

     Columns(1).AutoFit
Application.CutCopyMode = False

  Workbooks("table.csv").Activate
  
  Range("E2").Select
  closingratesecond = CDbl(ActiveCell.Value)
  Selection.Copy
  Workbooks("Part3.xlsm").Activate
  Sheets("Portfolio").Select
  Range(temppos).Select
  ActiveCell.Offset(0, 5).Select
  
  
      Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
   If closingratefirst <> 0 And closingratesecond <> 0 Then
   ActiveCell.Value = (closingratefirst / closingratesecond)
   Else
   ActiveCell.Value = "Not available"
   End If
   
   

ActiveCell.Select
Selection.NumberFormat = "0.00;[Red]0.00"

Workbooks("table.csv").Activate
On Error Resume Next
ActiveWorkbook.Close
End If

comingback:

Workbooks("Part3.xlsm").Activate
Range(temppos).Select

  


End Sub